List of usage examples for javax.swing JLabel setText
@BeanProperty(preferred = true, visualUpdate = true, description = "Defines the single line of text this component will display.") public void setText(String text)
From source file:Main.java
License:asdf
public static void main(String args[]) { JFrame f = new JFrame("Label Demo"); f.setLayout(new FlowLayout()); f.setSize(200, 360);/* ww w . java2 s. c om*/ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("asdf"); Border border = BorderFactory.createLineBorder(Color.BLACK); label.setBorder(border); label.setPreferredSize(new Dimension(150, 100)); label.setText("Centered"); label.setHorizontalAlignment(JLabel.CENTER); label.setVerticalAlignment(JLabel.CENTER); f.add(label); f.setVisible(true); }
From source file:Main.java
License:asdf
public static void main(String args[]) { JFrame f = new JFrame("Label Demo"); f.setLayout(new FlowLayout()); f.setSize(200, 360);/* www . java 2s . co m*/ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("asdf"); Border border = BorderFactory.createLineBorder(Color.BLACK); label.setBorder(border); label.setPreferredSize(new Dimension(150, 100)); label.setText("Top Left"); label.setHorizontalAlignment(JLabel.LEFT); label.setVerticalAlignment(JLabel.TOP); f.add(label); f.setVisible(true); }
From source file:Main.java
License:asdf
public static void main(String args[]) { JFrame f = new JFrame("Label Demo"); f.setLayout(new FlowLayout()); f.setSize(200, 360);/*w w w .j av a 2s . co m*/ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("asdf"); Border border = BorderFactory.createLineBorder(Color.BLACK); label.setBorder(border); label.setPreferredSize(new Dimension(150, 100)); label.setText("Bottom Right"); label.setHorizontalAlignment(JLabel.RIGHT); label.setVerticalAlignment(JLabel.BOTTOM); f.add(label); f.setVisible(true); }
From source file:Main.java
License:asdf
public static void main(String args[]) { JFrame f = new JFrame("Label Demo"); f.setLayout(new FlowLayout()); f.setSize(200, 360);/*from w w w. j a v a 2 s.co m*/ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("asdf"); Border border = BorderFactory.createLineBorder(Color.BLACK); label.setBorder(border); label.setPreferredSize(new Dimension(150, 100)); label.setText("Centered"); label.setHorizontalAlignment(JLabel.CENTER); label.setVerticalAlignment(JLabel.CENTER); f.add(label); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("Label Demo"); f.setLayout(new FlowLayout()); f.setSize(300, 200);// w ww. j a v a2 s. co m f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("java2s.com"); Border border = BorderFactory.createLineBorder(Color.BLACK); label.setBorder(border); label.setPreferredSize(new Dimension(150, 100)); label.setText("Centered"); label.setHorizontalAlignment(JLabel.CENTER); label.setVerticalAlignment(JLabel.CENTER); f.add(label); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Date date = new Date(); final JLabel timeLabel = new JLabel(date.toString()); Timer timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent e) { date.setTime(System.currentTimeMillis()); timeLabel.setText(date.toString()); }/*from w ww .j a v a 2 s . co m*/ }); timer.start(); JOptionPane.showMessageDialog(null, timeLabel); } }); }
From source file:tk.mystudio.ocr.OCRTest.java
public static void main(String[] args) { JFrame frame = new JFrame("??"); final JLabel label = new JLabel(new ImageIcon(), JLabel.CENTER); byte[] image = client.getCodeByte(Constants.LOGIN_CODE_URL); String randCodeByRob = OCR.read(image); label.setIcon(new ImageIcon(image)); label.setText(randCodeByRob); label.addMouseListener(new MouseAdapter() { @Override/* w ww .ja va 2 s .co m*/ public void mouseClicked(MouseEvent e) { byte[] image = client.getCodeByte(Constants.LOGIN_CODE_URL); String randCodeByRob = OCR.read(image); label.setIcon(new ImageIcon(image)); label.setText(randCodeByRob); System.out.println(randCodeByRob); } }); frame.add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JLabel label = new JLabel(); int timerDelay = 1000; new Timer(timerDelay, new ActionListener() { int timeLeft = 5; @Override// w w w. ja v a2 s. c om public void actionPerformed(ActionEvent e) { if (timeLeft > 0) { label.setText("Closing in " + timeLeft + " seconds"); timeLeft--; } else { ((Timer) e.getSource()).stop(); Window win = SwingUtilities.getWindowAncestor(label); win.setVisible(false); } } }) { { setInitialDelay(0); } }.start(); JOptionPane.showMessageDialog(null, label); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 300);//from www .j a v a 2s.c om JPanel panel = new JPanel(new GridLayout(3, 1)); JLabel label = new JLabel(); JTextField tf = new JTextField(); JButton b = new JButton("calc sting width"); b.addActionListener(e -> { FontMetrics fm = label.getFontMetrics(label.getFont()); String text = tf.getText(); int textWidth = fm.stringWidth(text); label.setText("text width for \"" + text + "\": " + textWidth); }); panel.add(label); panel.add(tf); panel.add(b); frame.setContentPane(panel); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { final MaskFormatter formatter = new TimeFormatter(); formatter.setValueClass(java.util.Date.class); final JFormattedTextField tf2 = new JFormattedTextField(formatter); tf2.setValue(new Date()); final JLabel label = new JLabel(); JButton bt = new JButton("Show Value"); bt.addActionListener(e -> {/* ww w . j a v a 2 s . c o m*/ System.out.println(" value 2 = " + tf2.getValue()); System.out.println(" value 2 = " + tf2.getText()); System.out.println("value class: " + formatter.getValueClass()); label.setText(tf2.getText()); }); JFrame f = new JFrame(); f.getContentPane().setLayout(new GridLayout()); f.getContentPane().add(tf2); f.getContentPane().add(label); f.getContentPane().add(bt); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }