List of usage examples for java.awt FlowLayout FlowLayout
public FlowLayout()
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JButton counterButton = new JButton("Clicked #0"); JButton closeButton = new JButton("Close"); frame.setLayout(new FlowLayout()); contentPane.add(closeButton);/*ww w . ja v a2 s . c om*/ contentPane.add(counterButton); counterButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { counterButton.setText("Clicked #" + counter++); } }); closeButton.addActionListener(e -> System.exit(0)); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(100, 75);/*from w ww. ja v a 2s . c o m*/ JPanel content = new JPanel(new FlowLayout()); frame.setContentPane(content); MaskFormatter formatter = new MaskFormatter("#"); formatter.setValidCharacters("123456789"); JFormattedTextField f1 = new JFormattedTextField(formatter); f1.setValue(null); f1.setColumns(1); content.add(f1); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JRadioButton button1 = new JRadioButton("Red"); JRadioButton button2 = new JRadioButton("Green"); JRadioButton button3 = new JRadioButton("Blue"); ButtonGroup colorButtonGroup = new ButtonGroup(); colorButtonGroup.add(button1);/* ww w .j a v a2s . c om*/ colorButtonGroup.add(button2); colorButtonGroup.add(button3); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Color:")); frame.add(button1); frame.add(button2); frame.add(button3); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); JPanel topPane = new JPanel(); JPanel midPane = new JPanel(); JPanel panesHolder = new JPanel(); JLabel label = new JLabel("Top label"); JTextField field = new JTextField(); field.setColumns(5);//from ww w .j a v a2s.c o m topPane.setLayout(new FlowLayout()); midPane.setLayout(new GridLayout(3, 2)); topPane.add(label); topPane.add(field); midPane.add(new JButton("Button 1")); midPane.add(new JButton("Button 2")); midPane.add(new JButton("A")); midPane.add(new JButton("H")); midPane.add(new JButton("I")); midPane.add(new JButton("T")); panesHolder.setLayout(new BoxLayout(panesHolder, BoxLayout.Y_AXIS)); panesHolder.add(topPane); panesHolder.add(midPane); frame.add(panesHolder); frame.setSize(400, 300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public static void main(String[] args) { JRadioButton button1 = new JRadioButton("Red"); JRadioButton button2 = new JRadioButton("Green"); JRadioButton button3 = new JRadioButton("Blue"); ButtonGroup colorButtonGroup = new ButtonGroup(); colorButtonGroup.add(button1);//from w ww.jav a 2s . co m colorButtonGroup.add(button2); colorButtonGroup.add(button3); button1.setSelected(true); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Color:")); frame.add(button1); frame.add(button2); frame.add(button3); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JComboBox<String> comboBox = new JComboBox<>(new String[] { "A", "B", "C" }); comboBox.setEditable(true);/*from w ww . ja va 2 s. c o m*/ JTextField editorComponent = (JTextField) comboBox.getEditor().getEditorComponent(); editorComponent.addActionListener(e -> { editorComponent.transferFocus(); }); JPanel panel = new JPanel(new FlowLayout()); panel.add(new JLabel("Field 1")); panel.add(comboBox); panel.add(new JLabel("Field 2")); panel.add(new JTextField(10)); panel.add(new JLabel("Field 3")); panel.add(new JTextField(10)); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); Container c = frame.getContentPane(); c.setLayout(new BorderLayout()); c.add(panel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { ImageIcon iconA = new ImageIcon("IconA.gif"); ImageIcon iconDiable = new ImageIcon("disable.gif"); ImageIcon iconOver = new ImageIcon("over.gif"); ImageIcon iconPressed = new ImageIcon("IconAPressed.gif"); final JButton jbtnA = new JButton("Alpha", iconA); JFrame jfrm = new JFrame(); jfrm.setLayout(new FlowLayout()); jfrm.setSize(300, 300);/*from w w w .j av a2s .c o m*/ jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jbtnA.setRolloverIcon(iconOver); jbtnA.setPressedIcon(iconPressed); jbtnA.setDisabledIcon(iconDiable); jfrm.getRootPane().setDefaultButton(jbtnA); jbtnA.setMnemonic(KeyEvent.VK_A); jbtnA.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("Alpha pressed. Beta is enabled."); jbtnA.setEnabled(!jbtnA.isEnabled()); } }); jfrm.add(jbtnA); jfrm.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { final JTextField textField = new JTextField(15); JButton buttonCut = new JButton("Cut"); JButton buttonPaste = new JButton("Paste"); JButton buttonCopy = new JButton("Copy"); JFrame jfrm = new JFrame("Cut, Copy, and Paste"); jfrm.setLayout(new FlowLayout()); jfrm.setSize(230, 150);/*from w ww. j a va 2s . com*/ jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); buttonCut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent le) { textField.cut(); } }); buttonPaste.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent le) { textField.paste(); } }); buttonCopy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent le) { textField.copy(); } }); textField.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent ce) { System.out.println("All text: " + textField.getText()); if (textField.getSelectedText() != null) System.out.println("Selected text: " + textField.getSelectedText()); else System.out.println("Selected text: "); } }); jfrm.add(textField); jfrm.add(buttonCut); jfrm.add(buttonPaste); jfrm.add(buttonCopy); jfrm.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); p.setOpaque(true);/*from w ww .j a va 2 s . co m*/ p.setLayout(new FlowLayout()); p.add(good); f.add(p, BorderLayout.CENTER); f.add(resultLabel, BorderLayout.SOUTH); good.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { resultLabel.setText("Working . . ."); good.setEnabled(false); Thread worker = new Thread() { public void run() { try { Thread.sleep(5000); } catch (InterruptedException ex) { } SwingUtilities.invokeLater(new Runnable() { public void run() { resultLabel.setText("Ready"); good.setEnabled(true); } }); } }; worker.start(); // So we don't hold up the dispatch thread. } }); f.setSize(300, 100); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JRadioButton button1 = new JRadioButton("Red"); JRadioButton button2 = new JRadioButton("Green"); JRadioButton button3 = new JRadioButton("Blue"); ButtonGroup colorButtonGroup = new ButtonGroup(); colorButtonGroup.add(button1);/* w w w .ja va 2 s . c o m*/ colorButtonGroup.add(button2); colorButtonGroup.add(button3); button1.setSelected(true); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Color:")); frame.add(button1); frame.add(button2); frame.add(button3); frame.pack(); frame.setVisible(true); System.out.println(getSelection(colorButtonGroup)); }