List of usage examples for javax.swing JLabel JLabel
public JLabel(Icon image)
JLabel
instance with the specified image. From source file:FormLayoutTester.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new FormLayout()); frame.add(new JLabel("A")); frame.add(new JTextField(15)); frame.add(new JLabel("AA")); frame.add(new JTextField(20)); frame.add(new JLabel("AAAA")); frame.add(new JTextField(10)); frame.add(new JLabel("AAAAAA")); frame.add(new JTextField(2)); frame.add(new JLabel("AAAAAAAA")); frame.add(new JTextField(5)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack();// w w w.j a va 2s.c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Focus Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);//ww w . j a v a 2s.co m panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH); frame.setSize(250, 150); frame.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 ww. j a va 2 s. c o 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
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 . ja v a2 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("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);//from w w w .j ava2 s .c o 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);/*www . j a v a 2 s .c o 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) throws Exception { File file = new File(args[0]); sun.awt.shell.ShellFolder sf = sun.awt.shell.ShellFolder.getShellFolder(file); Icon icon = new ImageIcon(sf.getIcon(true)); System.out.println("type = " + sf.getFolderType()); JLabel label = new JLabel(icon); JFrame frame = new JFrame(); frame.getContentPane().add(label);/*from w ww .j a va 2s . c o m*/ frame.pack(); frame.setVisible(true); }
From source file:SpringFormTest.java
public static void main(String args[]) { JFrame frame = new JFrame("Spring"); Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout);//from w ww .j av a2 s .c om Component left = new JLabel("Left"); Component right = new JTextField(15); contentPane.add(left); contentPane.add(right); layout.putConstraint(SpringLayout.WEST, left, 10, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, left, 25, SpringLayout.NORTH, contentPane); layout.putConstraint(SpringLayout.NORTH, right, 25, SpringLayout.NORTH, contentPane); layout.putConstraint(SpringLayout.WEST, right, 20, SpringLayout.EAST, left); frame.setSize(300, 100); frame.show(); }
From source file:MainClass.java
public static void main(String args[]) { JFrame f = new JFrame("JFormattedTextField Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box rowOne = Box.createHorizontalBox(); rowOne.add(new JLabel("SSN:")); try {//from w w w .ja va 2s. c o m MaskFormatter mf1 = new MaskFormatter("(###) ###-####"); rowOne.add(new JFormattedTextField(mf1)); } catch (ParseException e) { } f.add(rowOne, BorderLayout.NORTH); f.setSize(300, 100); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout()); gui.setBorder(new TitledBorder("Border Layout")); JPanel labels = new JPanel(); labels.setBorder(new TitledBorder("Flow Layout")); labels.add(new JLabel("Label 1")); labels.add(new JLabel("Label 2")); gui.add(labels, BorderLayout.NORTH); gui.add(new JButton("Button"), BorderLayout.SOUTH); JOptionPane.showMessageDialog(null, gui); }