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[]) { JPanel JMainPanel = new JPanel(new BorderLayout()); JPanel jp = new JPanel(); JComboBox combo = new JComboBox(new String[] { "Item1", "Item2", "Item3" }); JPanel jImage = new JPanel(); JFrame jf = new JFrame(); jp.add(combo);//w w w . j av a2s .c o m JMainPanel.add(jp, BorderLayout.WEST); JMainPanel.add(jImage, BorderLayout.CENTER); jp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_DOWN_MASK), "screenshot"); jp.getActionMap().put("screenshot", new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { final BufferedImage bf = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB); javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jf.getRootPane().paint(bf.getGraphics()); jImage.getGraphics().drawImage(bf, 0, 0, jImage); } }); } }); jf.getContentPane().add(JMainPanel); jf.setSize(500, 500); jf.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel statusBar = new JPanel(new FlowLayout(FlowLayout.LEFT)); statusBar.setBorder(new CompoundBorder(new LineBorder(Color.DARK_GRAY), new EmptyBorder(4, 4, 4, 4))); final JLabel status = new JLabel(); statusBar.add(status);//w w w . j a v a 2s .co m JLabel content = new JLabel("Content in the middle"); content.setHorizontalAlignment(JLabel.CENTER); final JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(content); frame.add(statusBar, BorderLayout.SOUTH); frame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { status.setText(frame.getWidth() + "x" + frame.getHeight()); } }); frame.setBounds(20, 20, 200, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { ImageIcon icon = new ImageIcon(new URL("http://www.java2s.com/style/download.png")); JLabel iconLabel = new JLabel(icon); JPanel iconPanel = new JPanel(new GridBagLayout()); iconPanel.add(iconLabel);/*from w w w.j a v a2 s. c om*/ JPanel textPanel = new JPanel(new GridLayout(0, 1)); for (int i = 0; i < 15; i++) { textPanel.add(new JLabel("Hello")); } JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(textPanel); mainPanel.add(iconPanel, BorderLayout.WEST); JOptionPane.showMessageDialog(null, mainPanel, "Center Image Dialog", JOptionPane.PLAIN_MESSAGE); }
From source file:Main.java
public static void main(String[] args) { JFrame jFrame = new JFrame(); jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jFrame.setSize(400, 300);/*from ww w . j a v a2s. com*/ JPanel panel = new JPanel(new FlowLayout()); jFrame.setContentPane(panel); JEditorPane editor = new JEditorPane(); new Main().remove_border(editor); panel.add(editor); jFrame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { List<Phone> phones = new ArrayList<>(); phones.add(new Phone("Galaxy", 12345)); phones.add(new Phone("iPhone", 12345)); JPanel panel = new JPanel(new GridLayout(0, 1)); for (Phone phone : phones) { String html = "<html><body style='width:100px'>Phone: " + phone.getName() + "<br/>Model: " + phone.getModel() + "</body></html>"; JLabel label = new JLabel(html); label.setBorder(new MatteBorder(0, 0, 1, 0, Color.BLACK)); panel.add(label);/*from w w w. ja va 2 s . co m*/ } JOptionPane.showMessageDialog(null, panel, "Phone List", JOptionPane.PLAIN_MESSAGE); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Offset Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); final JTextField textField = new JTextField(); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); JButton button = new JButton("Get Offset"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Offset: " + textField.getScrollOffset()); System.out.println("Visibility: " + textField.getHorizontalVisibility()); BoundedRangeModel model = textField.getHorizontalVisibility(); int extent = model.getExtent(); textField.setScrollOffset(extent); }//from ww w .j a v a 2s . c o m }; button.addActionListener(actionListener); frame.add(button, BorderLayout.SOUTH); frame.setSize(250, 150); frame.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);//from ww w . ja v a 2s .c o m 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); }
From source file:GridBagWithWeight.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of fill constraints"); JPanel p = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.weighty = 1.0;/*from www .j a va2s . c o m*/ c.weightx = 1.0; c.gridx = 0; c.gridy = 0; c.gridheight = 2; c.fill = GridBagConstraints.BOTH; // Use both horizontal & vertical p.add(new JButton("Java"), c); c.gridx = 1; c.gridheight = 1; c.gridwidth = 2; c.fill = GridBagConstraints.HORIZONTAL; // Horizontal only p.add(new JButton("Source"), c); c.gridy = 1; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; // Remember to reset to none p.add(new JButton("and"), c); c.gridx = 2; c.fill = GridBagConstraints.VERTICAL; // Vertical only p.add(new JButton("Support."), c); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:GridBagWithAnchor.java
public static void main(String[] args) { JFrame f = new JFrame("Demonstrates the use of anchor constraints"); JPanel p = new JPanel(new GridBagLayout()); p.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.weighty = 1.0;//www . ja va 2 s . c o m c.weightx = 1.0; c.gridx = 0; c.gridy = 0; c.gridheight = 2; c.anchor = GridBagConstraints.NORTH; // place component on the North p.add(new JButton("Java"), c); c.gridx = 1; c.gridheight = 1; c.gridwidth = 2; c.anchor = GridBagConstraints.SOUTHWEST; p.add(new JButton("Source"), c); c.gridy = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.CENTER; // remember to rest to center p.add(new JButton("and"), c); c.gridx = 2; p.add(new JButton("Support !!!"), c); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:FlatCheckBox.java
public static void main(String args[]) { JFrame frame = new JFrame("Flat CheckBox Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Pizza Toppings"); panel.setBorder(border);//from w w w. j a v a 2 s . co m JCheckBox check = new JCheckBox("Anchovies"); check.setBorderPaintedFlat(true); panel.add(check); check = new JCheckBox("Garlic"); panel.add(check); check = new JCheckBox("Onions"); check.setBorderPaintedFlat(true); panel.add(check); check = new JCheckBox("Pepperoni"); panel.add(check); check = new JCheckBox("Spinach"); check.setBorderPaintedFlat(true); panel.add(check); JButton button = new JButton("Submit"); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }