List of usage examples for javax.swing JLabel JLabel
public JLabel(Icon image)
JLabel
instance with the specified image. From source file:Main.java
public static void main(String[] args) { JTabbedPane tabbedPane;/* ww w .j a va2s . co m*/ JTextField txtFoo = new JTextField(10); JPanel pnlFoo = new JPanel(); pnlFoo.add(new JButton("Button 1")); pnlFoo.add(new JLabel("Foo")); pnlFoo.add(txtFoo); JTextField txtBar = new JTextField(10); JPanel pnlBar = new JPanel(); pnlBar.add(new JButton("Button 3")); pnlBar.add(new JLabel("Bar")); pnlBar.add(txtBar); tabbedPane = new JTabbedPane(); tabbedPane.addTab("Tab 1", pnlFoo); tabbedPane.addTab("Tab 2", pnlBar); tabbedPane.addChangeListener(e -> { Component comp = tabbedPane.getSelectedComponent(); if (comp.equals(pnlFoo)) { txtFoo.requestFocusInWindow(); } else if (comp.equals(pnlBar)) { txtBar.requestFocusInWindow(); } }); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(460, 200); frame.getContentPane().add(tabbedPane, BorderLayout.CENTER); frame.setVisible(true); txtFoo.requestFocusInWindow(); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Password Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel userPanel = new JPanel(new BorderLayout()); JLabel userLabel = new JLabel("Username: "); userLabel.setDisplayedMnemonic(KeyEvent.VK_U); JTextField userTextField = new JTextField(); userLabel.setLabelFor(userTextField); userPanel.add(userLabel, BorderLayout.WEST); userPanel.add(userTextField, BorderLayout.CENTER); JPanel passPanel = new JPanel(new BorderLayout()); JLabel passLabel = new JLabel("Password: "); passLabel.setDisplayedMnemonic(KeyEvent.VK_P); JPasswordField passTextField = new JPasswordField(); passLabel.setLabelFor(passTextField); passPanel.add(passLabel, BorderLayout.WEST); passPanel.add(passTextField, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); panel.add(userPanel, BorderLayout.NORTH); panel.add(passPanel, BorderLayout.SOUTH); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150);//w w w . j a va 2 s .co m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("GroupLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); GroupLayout groupLayout = new GroupLayout(contentPane); contentPane.setLayout(groupLayout);/*from w w w .j a va 2s . com*/ JLabel label = new JLabel("Label"); JButton b2 = new JButton("Second Button"); groupLayout.setHorizontalGroup( groupLayout.createSequentialGroup().addComponent(label).addGap(5, 10, 50).addComponent(b2)); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label).addComponent(b2)); frame.pack(); frame.setVisible(true); }
From source file:SpinnerDateSample.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SpinnerModel model1 = new SpinnerDateModel(); JSpinner spinner1 = new JSpinner(model1); JLabel label1 = new JLabel("Dates/Date"); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(label1, BorderLayout.WEST); panel1.add(spinner1, BorderLayout.CENTER); frame.add(panel1, BorderLayout.CENTER); frame.setSize(200, 90);//www.j a v a 2 s . c om frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JLabel("Auto Hide")); frame.pack();/*from w w w. j a v a2s . com*/ frame.setVisible(true); Timer autoHideTimer = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.dispose(); } }); autoHideTimer.setRepeats(false); frame.addMouseListener(new MouseAdapter() { @Override public void mouseExited(MouseEvent e) { System.out.println("Restart..."); autoHideTimer.restart(); } @Override public void mouseEntered(MouseEvent e) { System.out.println("Stop"); autoHideTimer.stop(); } }); }
From source file:Main.java
public static void main(String[] args) { Box box = Box.createVerticalBox(); for (int i = 1; i < 4; i++) { JPanel panel = new JPanel() { @Override// w ww . j a v a 2 s .c om public Dimension getMaximumSize() { return getPreferredSize(); } }; JLabel label1 = new JLabel("Label"); JLabel label2 = new JLabel(String.valueOf(i)); panel.add(label1); panel.add(label2); box.add(panel); } JFrame frame = new JFrame(); frame.add(box); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JLabel l = new JLabel("Text"); l.setBorder(new ThreeDimensionalBorder(Color.BLACK, 200, 5)); JOptionPane.showMessageDialog(null, l); }
From source file:BevelBorderWithDiffBorderColor.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border bevelBorder = new BevelBorder(BevelBorder.RAISED, Color.RED, Color.RED.darker(), Color.PINK, Color.PINK.brighter()); JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(bevelBorder);/*from ww w .j a va 2 s .co m*/ aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.setSize(240, 250);//from w ww. j a v a 2 s. c o m f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JScrollPane jscrlpLabel = new JScrollPane( new JLabel("<html>A<br>B<br>C<br>D<br>E<br>F<br>G<br>H<br></html>.")); jscrlpLabel.setPreferredSize(new Dimension(200, 100)); JLabel label = new JLabel("Option"); JCheckBox a = new JCheckBox("A"); JCheckBox b = new JCheckBox("B"); JCheckBox c = new JCheckBox("C"); JCheckBox d = new JCheckBox("D"); JCheckBox e = new JCheckBox("E"); Box box = Box.createVerticalBox(); box.add(label); box.add(a); box.add(b); box.add(c); box.add(d); box.add(e); JScrollPane jscrlpBox = new JScrollPane(box); jscrlpBox.setPreferredSize(new Dimension(140, 90)); f.add(jscrlpLabel); f.add(jscrlpBox); f.setVisible(true); }
From source file:MatteBorderSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Icon diamondIcon = new ImageIcon("yourImage.gif"); Border matteBorder = new MatteBorder(5, 10, 5, 10, diamondIcon); JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(matteBorder);//from www . j a v a2 s . co m aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }