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... args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel contentPane = new JPanel(); contentPane.setLayout(new GridLayout(1, 2, 2, 2)); JTextArea tArea1 = new JTextArea(); tArea1.setLineWrap(true);/*from w w w.j a va2 s . c o m*/ JTextArea tArea2 = new JTextArea(); tArea2.setLineWrap(true); tArea1.setText("I got a long long line of text in my JTextArea"); tArea2.setText("I got a long long line of text in my JTextArea"); JScrollPane scroller1 = new JScrollPane(); JScrollPane scroller2 = new JScrollPane(); scroller1.setViewportView(tArea1); scroller2.setViewportView(tArea2); contentPane.add(scroller1); contentPane.add(scroller2); frame.setContentPane(contentPane); frame.setSize(100, 100); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:SimpleGridBag.java
public static void main(String[] args) { JFrame f = new JFrame(); JPanel p = new JPanel(); p.setLayout(new GridBagLayout()); p.add(new JButton("Java")); p.add(new JButton("Source")); p.add(new JButton("and")); p.add(new JButton("Support.")); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/* w w w . ja va 2 s . c om*/ } }; f.addWindowListener(wndCloser); f.getContentPane().add(p); f.setSize(600, 200); f.show(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { MyTextField component = new MyTextField(10); MyTextField component2 = new MyTextField(10); JPanel p = new JPanel(); p.add(component);//from w w w . java2s . co m p.add(component2); JOptionPane.showMessageDialog(null, p); }
From source file:MyLabel.java
public static void main(String[] args) { String lyrics = "<html>Line<br>line<br>line</html>"; JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(10, 10)); JLabel label = new JLabel(lyrics); label.setFont(new Font("Georgia", Font.PLAIN, 14)); label.setForeground(new Color(50, 50, 25)); panel.add(label, BorderLayout.CENTER); panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JFrame f = new JFrame(); f.add(panel);/*from w w w . j a v a2 s . c o m*/ f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String items[] = { "Item1", "item1" }; JFrame f = new JFrame(); JPanel panel = new JPanel(); JComboBox<String> combo = new JComboBox<>(items); combo.setEditable(true);/*from w w w . j a v a2s . co m*/ JTextField txt = new JTextField(10); panel.add(combo); panel.add(txt); f.add(panel); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent ie) { String str = (String) combo.getSelectedItem(); txt.setText(str); } }); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(400, 100); f.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(); buttonPanel.addContainerListener(new ContainerListener() { public void componentAdded(ContainerEvent e) { displayMessage(" added to ", e); }//from w w w.j a v a 2 s . c o m public void componentRemoved(ContainerEvent e) { displayMessage(" removed from ", e); } void displayMessage(String action, ContainerEvent e) { System.out.println(((JButton) e.getChild()).getText() + " was" + action + e.getContainer().getClass().getName()); } }); buttonPanel.add(new JButton("A")); frame.add(buttonPanel); 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.DISPOSE_ON_CLOSE); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Table Title", TitledBorder.CENTER, TitledBorder.TOP)); JTable table = new JTable(3, 3); panel.add(new JScrollPane(table)); frame.add(panel);/* ww w . ja v a2 s.c om*/ frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JTabbedPane pane = new JTabbedPane(); pane.setUI(new SpacedTabbedPaneUI()); pane.addTab("One", new JPanel()); pane.addTab("Two", new JPanel()); pane.addTab("Threeeeeee", new JPanel()); pane.addTab("Four", new JPanel()); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(pane);/*from w w w . j a v a2s. c o m*/ frame.setSize(500, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); JPanel topPane = new JPanel(); JPanel midPane = new JPanel(); JPanel panesHolder = new JPanel(); JLabel label = new JLabel("Top label"); JTextField field = new JTextField(); field.setColumns(5);/*w w w. j a v a 2 s.c om*/ topPane.setLayout(new FlowLayout()); midPane.setLayout(new GridLayout(3, 2)); topPane.add(label); topPane.add(field); midPane.add(new JButton("Button 1")); midPane.add(new JButton("Button 2")); midPane.add(new JButton("A")); midPane.add(new JButton("H")); midPane.add(new JButton("I")); midPane.add(new JButton("T")); panesHolder.setLayout(new BoxLayout(panesHolder, BoxLayout.Y_AXIS)); panesHolder.add(topPane); panesHolder.add(midPane); frame.add(panesHolder); frame.setSize(400, 300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:DnDBetweenJTextAreaAndJTextFieldDemo.java
public static void main(String[] args) { JFrame frame = new JFrame("Drag and Drop Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new JPanel()); JTextField textField = new JTextField(25); textField.setText("www.java2s.com"); frame.add(textField);// w w w. j av a2 s.c o m JTextArea textArea = new JTextArea(4, 25); textArea.setText("Demonstrating\ndrag and drop"); frame.getContentPane().add(new JScrollPane(textArea)); textArea.setDragEnabled(true); textField.setDragEnabled(true); frame.pack(); frame.setVisible(true); }