List of usage examples for javax.swing JLabel JLabel
public JLabel(Icon image)
JLabel
instance with the specified image. From source file:TestOval.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label1 = new JLabel(new OvalIcon(20, 50)); JLabel label2 = new JLabel(new OvalIcon(50, 20)); JLabel label3 = new JLabel("Round!", new OvalIcon(60, 60), SwingConstants.CENTER); label3.setHorizontalTextPosition(SwingConstants.CENTER); Container c = f.getContentPane(); c.setLayout(new FlowLayout()); c.add(label1);/*from ww w .ja v a 2 s. c o m*/ c.add(label2); c.add(label3); f.pack(); f.setVisible(true); }
From source file:Main.java
License:asdf
public static void main(String args[]) { JFrame f = new JFrame("JPasswordField Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box rowOne = Box.createHorizontalBox(); rowOne.add(new JLabel("Username")); rowOne.add(new JTextField()); Box rowTwo = Box.createHorizontalBox(); rowTwo.add(new JLabel("Password")); JPasswordField jpassword = new JPasswordField(); rowTwo.add(jpassword);//from w w w. j a va 2 s. co m f.add(rowOne, BorderLayout.NORTH); f.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200); f.setVisible(true); jpassword.setText("asdf"); jpassword.selectAll(); jpassword.cut(); jpassword.copy(); jpassword.paste(); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); final JLabel valueLabel = new JLabel(String.valueOf(value)); JButton decButton = new JButton("-"); decButton.addActionListener(e -> valueLabel.setText(String.valueOf(--value))); JButton incButton = new JButton("+"); incButton.addActionListener(e -> valueLabel.setText(String.valueOf(++value))); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1;/* w ww. ja va 2 s. c om*/ c.gridx = 0; c.gridy = 0; panel.add(decButton, c); c.gridx = 1; panel.add(valueLabel, c); c.gridx = 2; panel.add(incButton, c); c.gridy = 1; int w = 32; for (c.gridx = 0; c.gridx < 3; c.gridx++) { panel.add(Box.createHorizontalStrut(w), c); } frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(final String[] args) { JFrame frame = new JFrame("Frame"); JDialog dialog = new JDialog(frame, "Dialog"); frame.add(new JLabel("Content")); frame.addMouseListener(new MouseAdapter() { @Override//from w w w.j a va 2s . c o m public void mousePressed(MouseEvent arg0) { System.out.println("frame pressed"); System.out.println("dialog focused " + dialog.isFocused()); System.out.println("frame focused " + frame.isFocused()); super.mousePressed(arg0); } }); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); dialog.add(new JLabel("Content")); dialog.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { super.focusLost(arg0); dialog.requestFocus(); } }); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); }
From source file:BoxSample.java
public static void main(String args[]) { JFrame horizontalFrame = new JFrame("Horizontal"); horizontalFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JLabel("Left")); horizontalBox.add(new JTextField("Middle")); horizontalBox.add(new JButton("Right")); horizontalFrame.add(horizontalBox, BorderLayout.CENTER); horizontalFrame.setSize(150, 150);// ww w . j ava 2s.c om horizontalFrame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setTitle("JLabel Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("First Name"); label.setFont(new Font("Courier New", Font.ITALIC, 12)); label.setForeground(Color.GRAY); frame.add(label);/*from w w w . jav a 2 s . com*/ frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); textField.setHorizontalAlignment(JTextField.CENTER); label.setLabelFor(textField);/*from www . j av a 2 s . com*/ panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.PAGE_START); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);/*from w ww .ja v a 2s . com*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.LINE_START); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);//w ww .j av a 2 s . c om frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box rowOne = new Box(BoxLayout.Y_AXIS); rowOne.add(new JLabel("Username")); rowOne.add(Box.createRigidArea(new Dimension(20, 20))); rowOne.add(new JTextField()); Component rowTwo = Box.createVerticalStrut(2); f.add(rowOne, BorderLayout.NORTH); f.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200);/* ww w. j av a 2 s .c om*/ f.setVisible(true); }