List of usage examples for javax.swing JPanel JPanel
public JPanel()
JPanel
with a double buffer and a flow layout. From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); System.out.println(layout.minimumLayoutSize(container)); container.setLayout(layout);/*w w w. jav a2 s .com*/ for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); System.out.println(layout.maximumLayoutSize(container)); container.setLayout(layout);/*from ww w . ja va 2 s . c o m*/ for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); System.out.println(layout.getAxis() == BoxLayout.Y_AXIS); container.setLayout(layout);//from w w w.j ava 2 s .co m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); JButton button = new JButton(); Main f = null;/* w ww. j a v a2 s . com*/ f = new Main(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(700, 400); panel1.setLayout(new BorderLayout()); panel1.setForeground(Color.white); button.setText("Convert"); panel1.add(button, BorderLayout.SOUTH); f.setContentPane(panel1); f.setVisible(true); f1 = new Main(); f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f1.setSize(457, 100); f1.setTitle("Conversion Progress"); f1.setLocationRelativeTo(null); panel2.setLayout(new BorderLayout()); panel2.setForeground(Color.white); JProgressBar progressBar = new JProgressBar(); progressBar.setValue(35); progressBar.setStringPainted(true); panel2.add(progressBar, BorderLayout.SOUTH); f1.setContentPane(panel2); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { f1.setVisible(true); } }); }
From source file:Main.java
public static final void main(String[] args) { JFrame frame = new JFrame(); JPanel mainPanel = new JPanel(); JPanel buttonsPanel = new JPanel(); frame.add(mainPanel);//from w ww .j a va2 s. c o m frame.add(buttonsPanel, BorderLayout.SOUTH); String[] options = { "S", "G", "I", "T" }; JComboBox comboBox = new JComboBox(options); comboBox.setRenderer(new MyComboBoxRenderer("COUNTRY")); comboBox.setSelectedIndex(-1); mainPanel.add(comboBox); JButton clearSelectionButton = new JButton("Clear selection"); clearSelectionButton.addActionListener(e -> { comboBox.setSelectedIndex(-1); }); buttonsPanel.add(clearSelectionButton); frame.pack(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);/* ww w . j a v a 2s . c o m*/ for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTabbedPane tabbedPane;//from www.jav a 2 s . c o m JTextField txtFoo = new JTextField(10); JPanel pnlFoo = new JPanel(); pnlFoo.add(new JButton("Button 1")); pnlFoo.add(new JLabel("Foo")); pnlFoo.add(txtFoo); JTextField txtBar = new JTextField(10); JPanel pnlBar = new JPanel(); pnlBar.add(new JButton("Button 3")); pnlBar.add(new JLabel("Bar")); pnlBar.add(txtBar); tabbedPane = new JTabbedPane(); tabbedPane.addTab("Tab 1", pnlFoo); tabbedPane.addTab("Tab 2", pnlBar); tabbedPane.addChangeListener(e -> { Component comp = tabbedPane.getSelectedComponent(); if (comp.equals(pnlFoo)) { txtFoo.requestFocusInWindow(); } else if (comp.equals(pnlBar)) { txtBar.requestFocusInWindow(); } }); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(460, 200); frame.getContentPane().add(tabbedPane, BorderLayout.CENTER); frame.setVisible(true); txtFoo.requestFocusInWindow(); }
From source file:Main.java
public static void main(String... args) { JPanel contentPane;/*from w w w .java2 s . co m*/ JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane = new JPanel(); contentPane.setLayout(new GridBagLayout()); JPanel centerPanel = new JPanel(); centerPanel.setOpaque(true); centerPanel.setBackground(Color.CYAN); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.FIRST_LINE_START; gbc.weightx = 1.0; gbc.weighty = 0.9; gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 2; gbc.fill = GridBagConstraints.BOTH; contentPane.add(centerPanel, gbc); JButton leftButton = new JButton("Left"); JButton rightButton = new JButton("Right"); gbc.gridwidth = 1; gbc.gridy = 1; gbc.weightx = 0.3; gbc.weighty = 0.1; contentPane.add(leftButton, gbc); gbc.gridx = 1; gbc.weightx = 0.7; gbc.weighty = 0.1; contentPane.add(rightButton, gbc); frame.setContentPane(contentPane); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] items = { "item1", "item2", "item1" }; JList<String> list = new JList<>(items); JTextField output = new JTextField(15); JPanel gui = new JPanel(); gui.add(list);/*from w w w . j a v a 2 s . c o m*/ gui.add(output); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent lse) { int index = list.getSelectedIndex(); String outputText = "Index: " + index + " Value: " + items[index]; output.setText(outputText); } }); JOptionPane.showMessageDialog(null, gui); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false);// w ww . j a v a 2s. co m frame.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); JPanel navigation_panel_wrap = new JPanel() { @Override public Dimension getPreferredSize() { return new Dimension(250, 700); } }; JPanel content_panel_wrap = new JPanel() { @Override public Dimension getPreferredSize() { return new Dimension(750, 700); } }; content_panel_wrap.setBackground(Color.green); navigation_panel_wrap.setBackground(Color.red); frame.add(navigation_panel_wrap); frame.add(content_panel_wrap); frame.pack(); frame.setVisible(true); }