jlabel

Fading a JLabel that contains html

余生长醉 提交于 2019-12-11 08:54:22
问题 I can fade out a normal JLabel using a Timer, as follows: public static void main(String[] args) { JFrame frame = new JFrame(); // final JLabel label = new JLabel("<html><font color=red>Red</font><font color=blue>Blue</font>"); final JLabel label = new JLabel("Hello"); label.setOpaque(true); label.setBackground(Color.WHITE); frame.getContentPane().add(label); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); final Timer timer = new Timer(100, null); final int steps = 25

setVisible(false) to a group of JTextField and JLabel

与世无争的帅哥 提交于 2019-12-11 08:46:01
问题 I have a group of JTextField and JLabel . I want them to initially not be visible so I thought to initialize my applet with a method which calls setVisible(false) for each of the components. Is it possible to create a method setVisible(false) which will set the visibility of all the components to false. Finally if I have 40 components in the applet, is it possible to do this with only one command instead of 40 commands? 回答1: Add your buttons and labels to a JPanel and then you can simply make

JLabel will not update unless something causes the method to hang

烂漫一生 提交于 2019-12-11 07:37:11
问题 Firstly, apologies but it would be really hard to reconstruct a SSCCE for this, though I think I can explain the situation considerably well and get my question across, My situation is as thus: I have a JLabel that serves as a status indicator (e.g. that will display "Loading..." or "Ready") and I call the setText method in a MouseAdapter before another method is called to do the actual action. However, the JLabel text never changes, unless I do something like call JOptionPane

Setting text of JLabel with an array/loop

耗尽温柔 提交于 2019-12-11 07:00:23
问题 How can I set the text of a JLabel with a loop? For example: String cur[]= {"A","B","C"}; JLabel lblA,lblB,lblC; for(i=0;i < cur.length;i++){ lbl+cur[i].setText("something"); } what should go in the "lbl+cur[i]" part so it sets the text of the JLabels? Thanks 回答1: You can't dynamically create variable names like that. If you want to set the value of a label in a loop then you need to create an array of JLabels the same way you create an array of Strings. JLabel[] labels = new JLabel[cur

Positioning GUI objects on a Frame

孤者浪人 提交于 2019-12-11 06:44:31
问题 I am developing a Java application and would like some help in positioning some Labels and TextFields. Here is my code: import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JComboBox; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JTextField; import java.awt.BorderLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.FlowLayout; public class AuctionClient { public AuctionClient(

Minimal way to make a cleanable drawing area

僤鯓⒐⒋嵵緔 提交于 2019-12-11 06:43:38
问题 I got a class with a resizable background. There are paintings over that background(using a paint method and Java2D). How can i delete everything that was drawn every time that the background gets a resize? (To eventually draw again in the correct places) Is there any sort of transform i can do on the already-drawn objects(like scaling to fit the image again)? import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import

Adding a JLabel to a Panel - how to layout the components properly?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 05:53:14
问题 I want to put some words in the frame so I used panel1.add(new JLabel("Hello")); But there are some buttons which their sizes and positions are customized. I heard that we have to setLayout(null) for the button customizing and this is also making the label not showing up. (Not sure if it is because of this) What is the solution for this? 回答1: I'll point you to the Java tutorials for laying out components - they give a good introduction to Swing formatting and layouts. Rather than calling

Show JLabel on JButton click

亡梦爱人 提交于 2019-12-11 05:44:31
问题 I want to see Jlabel when my show JButton is clicked, but it doesn't work! public class d5 extends JFrame implements ActionListener { JButton showButton; static JLabel[] lbl; JPanel panel; public d5() { showButton = new JButton("Show"); showButton.addActionListener(this); add(showButton, BorderLayout.PAGE_START); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 500); setLocation(300, 30); setVisible(true); } public JPanel mypanel() { panel = new JPanel(new FlowLayout(FlowLayout

Why does my program not change the font or size of the font when clicked in the JMenu?

与世无争的帅哥 提交于 2019-12-11 04:57:37
问题 When I try to run the program, it runs fine. The problem is that it does not change anything when the button is clicked. I think the problem is that it is not properly changing the Fonts. It does nothing even when I try to change the sizes but I do not know why that is. Thank you for helping! Here is the code to my program: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JMenuExample5 extends JFrame implements ActionListener{ Container con; JMenuBar menuBar;

Java Swing JLabels show in a buildGUI method but not if added from another method

邮差的信 提交于 2019-12-11 04:02:25
问题 I'm an amateur writing an archery score card. The programme works well but at the cost of 19 sections of identical code each of 18 lines. I'm trying to condense the code by using a method call. I'm using Java SE6 and Mig Layout Here is the section of code in the GUI which works. The GUI is called as below HomePage (containing the main method) -> ChoiceGUI -> buildScoresPanel public void buildScoresPanelMIG(JPanel scoresPanel) { for (row = 0; row<(int)numberofrows; row++){ scoresPanel.add