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[] argv) throws Exception { JButton component = new JButton(); JPanel panel = new JPanel(null); component.setBounds(1, 1, 100, 100); panel.add(component);// w ww .ja v a2s.c o m }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(new GridLayout(0, 5)); panel.add(new BasicArrowButton(BasicArrowButton.EAST)); panel.add(new BasicArrowButton(BasicArrowButton.NORTH)); panel.add(new BasicArrowButton(BasicArrowButton.SOUTH)); panel.add(new BasicArrowButton(BasicArrowButton.WEST)); JOptionPane.showMessageDialog(null, panel); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(new GridLayout(10, 10, 10, 10)); for (int i = 0; i < 100; i++) { panel.add(new JButton(String.valueOf(i))); }//from w w w . j a va 2 s. c om frame.add(panel); frame.setSize(600, 600); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel ui = new JPanel(new BorderLayout(1, 1)); JTabbedPane jtp = new JTabbedPane(JTabbedPane.LEFT); jtp.addTab("Apple", new JLabel("Apple")); jtp.addTab("Banana", new JLabel("Banana")); jtp.addTab("Cherries", new JLabel("Cherries")); jtp.addTab("Grapes", new JLabel("Grapes")); ui.add(jtp, BorderLayout.CENTER); jtp.setPreferredSize(new Dimension(200, 200)); jtp.addChangeListener(e -> {//w w w.j a va2s. co m if (e.getSource() instanceof JTabbedPane) { JTabbedPane pane = (JTabbedPane) e.getSource(); System.out.println("Selected paneNo : " + pane.getSelectedIndex()); } }); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout()); gui.setBorder(new TitledBorder("Border Layout")); JPanel labels = new JPanel(); labels.setBorder(new TitledBorder("Flow Layout")); labels.add(new JLabel("Label 1")); labels.add(new JLabel("Label 2")); gui.add(labels, BorderLayout.NORTH); gui.add(new JButton("Button"), BorderLayout.SOUTH); JOptionPane.showMessageDialog(null, gui); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new GridLayout(0, 1, 5, 5)); String[] speciesName = { "1", "2", "3" }; String[][] breedName = { { "A", "P", "A" }, { "B", "P", "S" }, { "DDo", "A", "P" } }; JComboBox<String> petSpecies = new JComboBox<>(speciesName); JComboBox<String> petBreed = new JComboBox<>(); petSpecies.addItemListener(e -> { int ii = petSpecies.getSelectedIndex(); ComboBoxModel cbm = new DefaultComboBoxModel(breedName[ii]); petBreed.setModel(cbm);/* www .j a v a 2s . c om*/ petBreed.requestFocusInWindow(); }); gui.add(petSpecies); gui.add(petBreed); JOptionPane.showMessageDialog(null, gui); }
From source file:Main.java
public static void main(String args[]) { JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);/*from w w w . j ava 2 s . c o m*/ panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel, BorderLayout.NORTH); frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(new JButton("A")); frame.add(buttonPanel);//from w ww .j av a 2 s . c o m frame.setSize(300, 200); frame.setVisible(true); }
From source file:BorderExample.java
public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); JPanel top = new JPanel(); top.setBackground(Color.gray); top.setPreferredSize(new Dimension(250, 150)); panel.add(top);// w ww . ja v a 2 s . c o m panel.setBorder(new EmptyBorder(new Insets(10, 20, 30, 40))); JFrame f = new JFrame(); f.add(panel); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextField smallField = new JTextField(5); JTextField largeField = new JTextField(20); JPanel gui = new JPanel(new FlowLayout()); gui.add(smallField);/*w w w . j a v a 2s.co m*/ gui.add(largeField); JFrame f = new JFrame("Text Field Size"); f.add(gui); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.pack(); f.setLocationByPlatform(true); f.setVisible(true); }