List of usage examples for javax.swing JFrame setLayout
public void setLayout(LayoutManager manager)
LayoutManager
. From source file:ImageDuplicity.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setLayout(new BorderLayout()); Component c = new ImageDuplicity(); f.add(c, BorderLayout.CENTER); f.setSize(200, 250);/*w w w .jav a2 s. c om*/ 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);/* ww w .j a va 2 s. 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); System.out.println(getSelection(colorButtonGroup)); }
From source file:JFileChooserTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("JComboBox Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Select File"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser fileChooser = new JFileChooser(); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); System.out.println(selectedFile.getName()); }// w w w .j av a2 s . c o m } }); frame.add(button); frame.pack(); frame.setVisible(true); }
From source file:JRadioButtonTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("JRadioButton Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JRadioButton button1 = new JRadioButton("Red"); JRadioButton button2 = new JRadioButton("Green"); JRadioButton button3 = new JRadioButton("Blue"); ButtonGroup colorButtonGroup = new ButtonGroup(); colorButtonGroup.add(button1);//w ww .ja v a2 s . c o m colorButtonGroup.add(button2); colorButtonGroup.add(button3); button1.setSelected(true); frame.add(new JLabel("Color:")); frame.add(button1); frame.add(button2); frame.add(button3); frame.pack(); frame.setVisible(true); }
From source file:JCheckBoxTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("JCheckBox Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox ac = new JCheckBox("A/C"); ac.setSelected(true);//from w w w . ja va2s . c o m JCheckBox cdPlayer = new JCheckBox("A"); JCheckBox cruiseControl = new JCheckBox("B"); JCheckBox keylessEntry = new JCheckBox("C"); JCheckBox antiTheft = new JCheckBox("D"); JCheckBox centralLock = new JCheckBox("E"); frame.add(new JLabel("Car Features")); frame.add(ac); frame.add(cdPlayer); frame.add(cruiseControl); frame.add(keylessEntry); frame.add(antiTheft); frame.add(centralLock); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JFrame parent = new JFrame("Parent Frame"); parent.setLayout(new FlowLayout()); parent.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); parent.setBounds(100, 100, 300, 200); parent.setVisible(true);//from ww w. ja v a2s .co m JDialog dialog1 = new JDialog(parent, "Dialog1 - Modeless Dialog"); dialog1.setBounds(200, 200, 300, 200); dialog1.setVisible(true); JDialog dialog2 = new JDialog(parent, "Dialog2 - Document-Modal Dialog", Dialog.ModalityType.DOCUMENT_MODAL); dialog2.setBounds(300, 300, 300, 200); JDialog dialog3 = new JDialog(dialog2, "Dialog3 - Modeless Dialog"); dialog3.setBounds(400, 400, 300, 200); dialog3.setVisible(true); dialog2.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 . ja va 2 s . 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[]) { JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.setSize(240, 250);/*from w ww . j a va 2s. c om*/ 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:ApplicationModalDialogWithExcludeDemo.java
public static void main(String[] args) { final JFrame parent1 = new JFrame("Parent Frame 1"); parent1.setLayout(new FlowLayout()); parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); parent1.setBounds(100, 100, 200, 150); parent1.setVisible(true);/*from www.jav a2 s . com*/ JFrame parent2 = new JFrame("Parent Frame 2"); parent2.setBounds(500, 100, 300, 150); parent2.setVisible(true); JFrame parent3 = new JFrame("Parent Frame 3 - Excluded"); parent3.setBounds(300, 400, 300, 150); parent3.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); parent3.setVisible(true); JDialog dialog = new JDialog(parent1, "Application-Modal Dialog", Dialog.ModalityType.APPLICATION_MODAL); dialog.setBounds(300, 200, 300, 150); dialog.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 .j a v a2s.c o m*/ frame.pack(); frame.setVisible(true); }