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[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);/*from w w w . j a va 2 s . c o m*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { Main t = new Main(); JPanel mainPanel = new JPanel(new BorderLayout()); JLabel l = new JLabel("hello world"); l.setOpaque(true);/*w w w . j a va 2 s .c o m*/ l.setBackground(Color.RED); JPanel extraPanel = new JPanel(new FlowLayout()); l.setPreferredSize(new Dimension(100, 100)); extraPanel.setBackground(Color.GREEN); extraPanel.add(l); mainPanel.add(extraPanel, BorderLayout.CENTER); t.setContentPane(mainPanel); t.setDefaultCloseOperation(EXIT_ON_CLOSE); t.setSize(400, 200); t.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout(2, 2)); BufferedImage bi = new BufferedImage(600, 200, BufferedImage.TYPE_INT_RGB); gui.add(new JLabel(new ImageIcon(bi))); JFrame myframe = new JFrame(); JPanel myPanel = new JPanel(); gui.add(myPanel, BorderLayout.PAGE_END); myPanel.setLayout(new GridLayout(2, 0, 0, 0)); int x = 0;//from w ww.jav a2 s . c o m int y = 5; for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) { myPanel.add(new JButton(alphabet + "")); x++; if (x > 15) { y = 6; x = 0; } } myframe.add(gui); myframe.pack(); myframe.setVisible(true); myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); String[] values = new String[] { "One", "Two", "Three" }; JComboBox<String> comboBox = new JComboBox<>(values); panel.add(comboBox, BorderLayout.NORTH); JTextArea textArea = new JTextArea(2, 2); panel.add(textArea, BorderLayout.CENTER); JButton button = new JButton("Action"); button.addActionListener(new ActionListener() { @Override/*from ww w. j av a 2 s . c om*/ public void actionPerformed(ActionEvent e) { textArea.setText((String) comboBox.getSelectedItem()); comboBox.setSelectedIndex(0); } }); panel.add(button, BorderLayout.SOUTH); JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:MainFrameBorderLayout.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.BEFORE_FIRST_LINE); frame.add(outerPanel);//from ww w. j a va 2s. c om frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel ui = new JPanel(new BorderLayout(2, 2)); ui.setBorder(new EmptyBorder(4, 4, 4, 4)); JPanel controls = new JPanel(new BorderLayout(2, 2)); ui.add(controls, BorderLayout.PAGE_START); String s = new String(Character.toChars(8594)); String[] items = { "Choice: right " + s + " arrow" }; JComboBox cb = new JComboBox(items); controls.add(cb, BorderLayout.CENTER); controls.add(new JButton("Button"), BorderLayout.LINE_END); JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JTextArea(4, 40), new JTextArea(4, 40)); ui.add(sp, BorderLayout.CENTER); JFrame f = new JFrame("Stretch Combo Layout"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setContentPane(ui);//ww w . j a v a2s . c om f.pack(); f.setLocationByPlatform(true); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(new GridBagLayout()); for (int i = 0; i < 25; i++) { JTextField field = new JTextField("Field " + i, 20); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridy = i;//from w w w .j a v a 2s .c o m panel.add(field, constraints); } JScrollPane scrollPane = new JScrollPane(panel); JButton removeButton = new JButton("Remove Field"); removeButton.addActionListener(e -> { if (panel.getComponentCount() >= 1) { panel.remove(panel.getComponentCount() - 1); scrollPane.revalidate(); scrollPane.repaint(); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(640, 480); f.setLocation(200, 200); f.getContentPane().add(scrollPane); f.getContentPane().add(removeButton, BorderLayout.SOUTH); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) throws Exception { 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 . ja va2 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); textField.setText("your text"); String filename = "test.txt"; FileWriter writer = new FileWriter(filename); textField.write(writer); writer.close(); }
From source file:Main.java
public static void main(String[] args) { int specificX = 40; int specificY = 20; JPanel gui = new JPanel(new BorderLayout()); JTextField tf = new JTextField(10); JPanel borderPanel = new JPanel(new GridLayout()); borderPanel.add(tf);//from w ww. j a v a2s .com borderPanel.setBorder(new EmptyBorder(specificX, specificY, specificX, specificY)); borderPanel.setBackground(Color.GREEN); gui.add(borderPanel); JOptionPane.showMessageDialog(null, gui); }
From source file:Main.java
public static void main(String[] args) { Image image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); JPanel gui = new JPanel(new BorderLayout()); JLabel clouds = new JLabel(new ImageIcon(new BufferedImage(250, 100, BufferedImage.TYPE_INT_RGB))); gui.add(clouds);// w w w. j a va 2s . c o m JOptionPane.showConfirmDialog(null, gui, "Title", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon(image)); }