List of usage examples for javax.swing JPanel JPanel
public JPanel(boolean isDoubleBuffered)
JPanel
with FlowLayout
and the specified buffering strategy. From source file:Main.java
public static void main(String[] args) throws Exception { String[] columns = { "Name", "Age" }; Object[][] content = { { "R", new Integer(24) }, { "A", new Integer(25) }, { "J", new Integer(30) }, { "A", new Integer(32) }, { "S", new Integer(27) } }; JTable table = new JTable(content, columns); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel jPanel = new JPanel(new GridLayout(2, 0)); jPanel.setOpaque(true);//from w w w . j a v a 2s . c o m table.setPreferredScrollableViewportSize(new Dimension(500, 70)); jPanel.add(new JScrollPane(table)); /* Add the panel to the JFrame */ frame.add(jPanel); /* Display the JFrame window */ frame.pack(); frame.setVisible(true); table.print(); }
From source file:JRadioButtonSelectedElements.java
public static void main(String args[]) { JFrame frame = new JFrame("Grouping Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); ButtonGroup group = new ButtonGroup(); JRadioButton aRadioButton = new JRadioButton("A"); JRadioButton bRadioButton = new JRadioButton("B"); ActionListener crustActionListener = new ActionListener() { String lastSelected;//from www .j a va 2 s. c o m public void actionPerformed(ActionEvent actionEvent) { AbstractButton aButton = (AbstractButton) actionEvent.getSource(); String label = aButton.getText(); String msgStart; if (label.equals(lastSelected)) { msgStart = "Reselected: "; } else { msgStart = "Selected: "; } lastSelected = label; System.out.println(msgStart + label); } }; panel.add(aRadioButton); group.add(aRadioButton); panel.add(bRadioButton); group.add(bRadioButton); aRadioButton.addActionListener(crustActionListener); bRadioButton.addActionListener(crustActionListener); frame.add(panel); frame.setSize(300, 200); frame.setVisible(true); System.out.println(getSelectedElements(panel).hasMoreElements()); }
From source file:Main.java
public static void main(String[] args) { try {// w w w . j a v a2 s . c o m bg = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); } catch (Exception ex) { System.out.println(ex); } JPanel tabPanel = new JPanel(new GridBagLayout()) { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(bg, 0, 0, getWidth(), getHeight(), this); } @Override public Dimension getPreferredSize() { return new Dimension(400, 300); } }; JPanel buttons = new JPanel(new GridLayout(4, 1, 15, 15)); buttons.setOpaque(false); for (int i = 0; i < 4; i++) { buttons.add(new JButton("Button")); } tabPanel.add(buttons); JTabbedPane tabPane = new JTabbedPane(); tabPane.add("Panel with Bachground", tabPanel); JFrame frame = new JFrame(); frame.setContentPane(tabPane); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setUndecorated(true);// w w w. ja v a 2 s.com frame.setBackground(new Color(0, 0, 0, 0)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new ShadowPane()); JPanel panel = new JPanel(new GridBagLayout()); panel.add(new JLabel("Look ma, no hands")); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("js"); String[] ops = { "+", "-", "*", "/" }; JPanel gui = new JPanel(new BorderLayout(2, 2)); JPanel labels = new JPanel(new GridLayout(0, 1)); gui.add(labels, BorderLayout.WEST); labels.add(new JLabel("a")); labels.add(new JLabel("operand")); labels.add(new JLabel("b")); labels.add(new JLabel("=")); JPanel controls = new JPanel(new GridLayout(0, 1)); gui.add(controls, BorderLayout.CENTER); JTextField a = new JTextField(10); controls.add(a);/*from w w w. j a v a2 s . c o m*/ JComboBox operand = new JComboBox(ops); controls.add(operand); JTextField b = new JTextField(10); controls.add(b); JTextField output = new JTextField(10); controls.add(output); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { String expression = a.getText() + operand.getSelectedItem() + b.getText(); try { Object result = engine.eval(expression); if (result == null) { output.setText("Output was 'null'"); } else { output.setText(result.toString()); } } catch (ScriptException se) { output.setText(se.getMessage()); } } }; operand.addActionListener(al); a.addActionListener(al); b.addActionListener(al); JOptionPane.showMessageDialog(null, gui); }
From source file:SpinnerNumberEditorSample2.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SpinnerModel model = new SpinnerNumberModel(50, 0, 100, .25); JSpinner spinner = new JSpinner(model); JComponent editor = new JSpinner.NumberEditor(spinner, "#,##0.###"); spinner.setEditor(editor);/* w w w. j a va 2s. c o m*/ JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(spinner, BorderLayout.CENTER); frame.add(panel1, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new GridLayout(0, 1, 3, 15)); for (int ii = 1; ii < 4; ii++) { gui.add(getButtonLayout(ii));//from w ww . ja v a 2s. c om } JOptionPane.showMessageDialog(null, gui); }
From source file:AButtonGroup.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 w w 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); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Options"); panel.setBorder(border);//from w ww. java 2s . c om 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); } }; JButton button = new JButton("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) { JFrame f = new JFrame(); f.setTitle("Example2"); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p1.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 1")); for (int i = 0; i < NB1; i++) p1.add(new JButton("Button " + i)); JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p2.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 2")); for (int i = NB1; i < NB2; i++) p2.add(new JButton("Button " + i)); JPanel p3 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p3.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 3")); for (int i = NB2; i < NB3; i++) p3.add(new JButton("Button " + i)); JPanel global = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; // added gbc.weightx = 1.0f; // added gbc.gridy = 0;//w ww. jav a 2 s . com global.add(p1, gbc); gbc.gridy++; global.add(p2, gbc); gbc.gridy++; global.add(p3, gbc); f.add(global); f.pack(); f.setVisible(true); }