List of usage examples for javax.swing JPanel JPanel
public JPanel(boolean isDoubleBuffered)
JPanel
with FlowLayout
and the specified buffering strategy. From source file:GridLayoutDemo.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(new GridLayout(1, 0)); p.add(createComponent("Component 1")); p.add(createComponent("Component 2")); p.add(createComponent("Component 3")); p.add(createComponent("Component 4")); frame.setContentPane(p);/* ww w . j a va2 s .c o m*/ //Display the window. frame.pack(); frame.setVisible(true); }
From source file:FindingAButtonGroup.java
public static void main(String args[]) { JFrame frame = new JFrame("Button Group"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Examples"); panel.setBorder(border);//from ww w . ja v a2 s . c om ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JToggleButton("Toggle Button"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Radio Button"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JCheckBox("Check Box"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item"); panel.add(abstract5); group.add(abstract5); frame.add(panel, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); group.setSelected(abstract1.getModel(), true); Enumeration elements = group.getElements(); while (elements.hasMoreElements()) { AbstractButton button = (AbstractButton) elements.nextElement(); if (button.isSelected()) { System.out.println("The winner is: " + button.getText()); } } }
From source file:Main.java
public static void main(String[] args) { JLabel userLabel = new JLabel("User Name"); JLabel passLabel = new JLabel("Password"); JTextField userText = new JTextField(20); JPasswordField passText = new JPasswordField(20); JButton loginButton = new JButton("Login"); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(4, 4, 4, 4); gbc.gridx = 0;// w w w . j a v a 2 s.c om gbc.gridy = 0; gbc.fill = GridBagConstraints.NONE; panel.add(userLabel, gbc); gbc.gridx = 1; gbc.gridy = 0; gbc.fill = GridBagConstraints.HORIZONTAL; panel.add(userText, gbc); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.NONE; panel.add(passLabel, gbc); gbc.gridx = 1; gbc.gridy = 1; gbc.fill = GridBagConstraints.HORIZONTAL; panel.add(passText, gbc); gbc.gridx = 0; gbc.gridy = 2; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.CENTER; gbc.gridwidth = 2; panel.add(loginButton, gbc); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(panel)); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:ASelectedButton.java
public static void main(String args[]) { JFrame frame = new JFrame("Radio Buttons"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Options"); panel.setBorder(border);/* w w w . jav a 2 s .co m*/ final ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JRadioButton("One"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Two"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JRadioButton("Three"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButton("Four"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JRadioButton("Five"); panel.add(abstract5); group.add(abstract5); ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { Enumeration elements = group.getElements(); while (elements.hasMoreElements()) { AbstractButton button = (AbstractButton) elements.nextElement(); if (button.isSelected()) { System.out.println("The winner is: " + button.getText()); break; } } group.setSelected(null, true); } }; JToggleButton button = new JToggleButton("Show Selected"); button.addActionListener(aListener); Container container = frame.getContentPane(); container.add(panel, BorderLayout.CENTER); container.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { NumberFormat numberFormatGuFalse = NumberFormat.getNumberInstance(); numberFormatGuFalse.setGroupingUsed(false); JFormattedTextField jftFieldGuFalse = new JFormattedTextField(numberFormatGuFalse); NumberFormat numberFormatGuTrue = NumberFormat.getNumberInstance(); // numberFormatGuFalse.setGroupingUsed(true); // not necessary as is default JFormattedTextField jftFieldGuTrue = new JFormattedTextField(numberFormatGuTrue); JPanel panel = new JPanel(new BorderLayout()); panel.add(jftFieldGuFalse, BorderLayout.NORTH); panel.add(jftFieldGuTrue, BorderLayout.SOUTH); JFrame frame = new JFrame(); frame.getContentPane().add(panel);/* w ww. ja v a2 s . c om*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:SettingSelectedAButtonGroup.java
public static void main(String args[]) { JFrame frame = new JFrame("Button Group"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Examples"); panel.setBorder(border);//from www .j a va 2s. c o m ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JToggleButton("Toggle Button"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Radio Button"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JCheckBox("Check Box"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item"); panel.add(abstract5); group.add(abstract5); frame.add(panel, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); group.setSelected(abstract1.getModel(), true); Enumeration elements = group.getElements(); while (elements.hasMoreElements()) { AbstractButton button = (AbstractButton) elements.nextElement(); if (button.isSelected()) { System.out.println("The winner is: " + button.getText()); } } }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(Main.class.getSimpleName()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BufferedImage bi = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel(new ImageIcon(bi)); panel.add(label);// w ww.ja v a 2 s . c om MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1); ((JPanel) e.getSource()).scrollRectToVisible(r); } }; panel.addMouseMotionListener(doScrollRectToVisible); panel.setAutoscrolls(true); f.add(new JScrollPane(panel)); f.pack(); f.setSize(f.getWidth() / 2, f.getHeight() / 2); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH); String days[] = symbols.getWeekdays(); SpinnerModel model1 = new SpinnerListModel(days); JSpinner spinner1 = new JSpinner(model1); JLabel label1 = new JLabel("French Days/List"); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(label1, BorderLayout.WEST); panel1.add(spinner1, BorderLayout.CENTER); frame.add(panel1, BorderLayout.NORTH); frame.setSize(200, 90);/*from ww w .j av a 2 s. co m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { FlowLayout layout = new FlowLayout(FlowLayout.LEADING, horizontalGap, verticalGap); JButton button = new JButton("Discard"); JLabel[] panels = new JLabel[5]; JFrame frame = new JFrame("Poker"); frame.setSize(width, height);//ww w.j ava 2 s. c o m frame.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); JPanel deckPanel = new JPanel(layout); for (int i = 0; i < 5; i++) { panels[i] = new JLabel("" + i); deckPanel.add(panels[i]); } frame.getContentPane().add(deckPanel); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); buttonPanel.add(button); frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:SpinnerStringsSample.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH); String days[] = symbols.getWeekdays(); SpinnerModel model1 = new SpinnerListModel(days); JSpinner spinner1 = new JSpinner(model1); JLabel label1 = new JLabel("French Days/List"); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(label1, BorderLayout.WEST); panel1.add(spinner1, BorderLayout.CENTER); frame.add(panel1, BorderLayout.NORTH); frame.setSize(200, 90);/*w w w . j a va 2 s . com*/ frame.setVisible(true); }