List of usage examples for javax.swing JFrame setLayout
public void setLayout(LayoutManager manager)
LayoutManager
. From source file:Main.java
public static void main(String[] args) { final JTextPane tp = new JTextPane(); JButton withFocus = new JButton("Select with focus"); withFocus.addActionListener(e -> { tp.selectAll();//w w w . j a va 2s. c o m tp.requestFocus(); }); JButton withOutFocus = new JButton("Select without focus"); withFocus.addActionListener(e -> tp.selectAll()); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(tp)); JPanel panel = new JPanel(); panel.add(withFocus); panel.add(withOutFocus); frame.add(panel, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.setSize(100, 100);/* w w w. ja va 2 s. c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JButton ok = new JButton("ok"); JCheckBox cb = new JCheckBox("Enabled", true); cb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (ok.isEnabled()) ok.setEnabled(false);//from w ww. ja v a 2 s .c om else ok.setEnabled(true); } }); ButtonModel model = new DefaultButtonModel() { public void setEnabled(boolean b) { if (b) System.out.println("Pressed: true"); else System.out.println("Pressed: false"); super.setEnabled(b); } public void setArmed(boolean b) { if (b) System.out.println("Armed: true"); else System.out.println("Armed: false"); super.setArmed(b); } public void setPressed(boolean b) { if (b) System.out.println("Pressed: true"); else System.out.println("Pressed: false"); super.setPressed(b); } }; ok.setModel(model); JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.add(ok); f.add(cb); f.setSize(350, 250); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { Locale locale = Locale.getDefault(); ResourceBundle rb = ResourceBundle.getBundle("MyResources", locale); JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("I18N Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 2)); frame.add(new JLabel(rb.getString("userName"))); frame.add(new JTextField()); frame.add(new JLabel(rb.getString("password"))); frame.add(new JPasswordField()); frame.add(new JButton(rb.getString("login"))); frame.pack();//from ww w. j a v a 2 s .c o m frame.setVisible(true); }
From source file:GridLayoutTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("GridLayout Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 2)); frame.add(new JButton("Button 1")); frame.add(new JButton("Button 2")); frame.add(new JButton("Button 3")); frame.add(new JButton("Button 4")); frame.add(new JButton("Button 5")); frame.add(new JButton("Button 6")); frame.add(new JButton("Button 7")); frame.add(new JButton("Button 8")); frame.pack();// www. j a v a2s . c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JLabel("Hit Escape to exit full screen", JLabel.CENTER), BorderLayout.CENTER); frame.setSize(300, 300);//from www . j a v a 2 s .c o m KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke("ESCAPE"); Action escapeAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .setFullScreenWindow(null); } }; frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE"); frame.getRootPane().getActionMap().put("ESCAPE", escapeAction); GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame); }
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 ww w. j a v a 2 s . c o m 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 frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.pack();//from www .j a va 2s . c o m Container contentPane = frame.getContentPane(); contentPane.setLayout(null); for (int i = 0; i < 4; i++) { JPanel panel = new JPanel(); panel.setBounds((i * 75) + 475, 25, 75, 100); System.out.println(panel.getBounds()); contentPane.add(panel); panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 3)); } System.out.println(getComponentAt(contentPane, new Point(475, 25))); System.out.println(getComponentAt(contentPane, new Point(100, 25))); frame.setVisible(true); }
From source file:JButtonKnowsBgColor.java
public static void main(String[] args) { JButtonKnowsBgColor jbkbc = new JButtonKnowsBgColor("choose back", Color.RED, true); JButtonKnowsBgColor jbkbc1 = new JButtonKnowsBgColor("choose fore", Color.BLUE, false); JFrame jf = new JFrame(); jf.setLayout(new BorderLayout()); jf.getContentPane().add(jbkbc, BorderLayout.NORTH); jf.getContentPane().add(jbkbc1, BorderLayout.CENTER); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(100, 200);/*ww w .jav a 2s .co m*/ jf.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JLabel label = new JLabel("java2s.com"); JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(label);/*w w w . j a va2 s . c om*/ JPanel buttons = new JPanel(new GridLayout(0, 1)); for (int index = 0; index < 10; index++) { buttons.add(new JButton(String.valueOf(index))); } JPanel right = new JPanel(new BorderLayout()); right.add(buttons, BorderLayout.NORTH); frame.add(right, BorderLayout.EAST); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }