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 controlPane = new JPanel(); JPanel buttonPane = new JPanel(); controlPane.setLayout(new BoxLayout(controlPane, BoxLayout.PAGE_AXIS)); controlPane.setPreferredSize(new Dimension(200, 200)); controlPane.add(new JScrollPane(new JTextArea())); buttonPane.setLayout(new FlowLayout(FlowLayout.LEFT)); buttonPane.setPreferredSize(new Dimension(100, 40)); buttonPane.add(new JButton("Button1")); buttonPane.add(new JButton("Button2")); frame.add(controlPane, BorderLayout.NORTH); frame.add(buttonPane, BorderLayout.SOUTH); frame.pack();//w ww .j ava2 s .com frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame window = new JFrame("Example"); JPanel contentPane = new JPanel(); contentPane.setLayout(new GridBagLayout()); JComboBox comboBoxfields = new JComboBox(COMBO_BOX_ELEMENTS); comboBoxfields.setFont(new Font("sansserif", Font.TRUETYPE_FONT | Font.PLAIN, 15)); comboBoxfields.setBorder(new SoftBevelBorder(BevelBorder.LOWERED)); comboBoxfields.setMaximumRowCount(5); comboBoxfields.addActionListener(//w w w. j av a2 s .co m e -> System.out.println("'" + comboBoxfields.getSelectedItem().toString() + "'" + " was selected")); contentPane.add(comboBoxfields); window.add(contentPane); window.setSize(500, 500); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel topPanel = new JPanel(); topPanel.setPreferredSize(new Dimension(200, 200)); topPanel.setBackground(Color.WHITE); JTextArea chatArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(chatArea); JPanel mainPanel = new JPanel(new BorderLayout(5, 5)); mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); mainPanel.add(topPanel, BorderLayout.CENTER); mainPanel.add(scrollPane, BorderLayout.SOUTH); chatArea.getDocument().addDocumentListener(new DocumentListener() { @Override//www . j a v a 2 s . co m public void insertUpdate(DocumentEvent e) { updateLineCount(); } @Override public void removeUpdate(DocumentEvent e) { updateLineCount(); } @Override public void changedUpdate(DocumentEvent e) { updateLineCount(); } private void updateLineCount() { int lineCount = chatArea.getLineCount(); if (lineCount <= 4) { chatArea.setRows(lineCount); mainPanel.revalidate(); } } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(mainPanel); f.pack(); f.setVisible(true); }
From source file:OverlaySample.java
public static void main(String args[]) { JFrame frame = new JFrame("Overlay Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { public boolean isOptimizedDrawingEnabled() { return false; }//from w w w . j a va 2 s . c o m }; LayoutManager overlay = new OverlayLayout(panel); panel.setLayout(overlay); JButton button = new JButton("Small"); button.setMaximumSize(new Dimension(25, 25)); button.setBackground(Color.white); panel.add(button); button = new JButton("Medium"); button.setMaximumSize(new Dimension(50, 50)); button.setBackground(Color.gray); panel.add(button); button = new JButton("Large"); button.setMaximumSize(new Dimension(100, 100)); button.setBackground(Color.black); panel.add(button); frame.add(panel, BorderLayout.CENTER); frame.setSize(400, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("CardLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JPanel buttonPanel = new JPanel(); JButton nextButton = new JButton("Next"); buttonPanel.add(nextButton);//w ww . j a v a2 s. c o m contentPane.add(buttonPanel, BorderLayout.SOUTH); final JPanel cardPanel = new JPanel(); final CardLayout cardLayout = new CardLayout(); cardPanel.setLayout(cardLayout); for (int i = 1; i <= 5; i++) { JButton card = new JButton("Card " + i); card.setPreferredSize(new Dimension(200, 200)); String cardName = "card" + 1; cardPanel.add(card, cardName); } contentPane.add(cardPanel, BorderLayout.CENTER); nextButton.addActionListener(e -> cardLayout.next(cardPanel)); frame.pack(); frame.setVisible(true); }
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(); JTextField tField = new JTextField(10); ((AbstractDocument) tField.getDocument()).setDocumentFilter(new MyDocumentFilter()); contentPane.add(tField);/*from w ww.j av a2s . com*/ frame.setContentPane(contentPane); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Overlay Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { public boolean isOptimizedDrawingEnabled() { return false; }//w w w. j a v a 2s .c o m }; LayoutManager overlay = new OverlayLayout(panel); panel.setLayout(overlay); JButton button = new JButton("Small"); button.setMaximumSize(new Dimension(25, 25)); button.setBackground(Color.white); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); button = new JButton("Medium"); button.setMaximumSize(new Dimension(50, 50)); button.setBackground(Color.gray); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); button = new JButton("Large"); button.setMaximumSize(new Dimension(100, 100)); button.setBackground(Color.black); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); frame.add(panel, BorderLayout.CENTER); frame.setSize(400, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame aWindow = new JFrame("This is a Border Layout"); aWindow.setBounds(30, 30, 300, 300); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); p.add(new JTextField(10)); p.add(new JTextField(10)); p.add(new JTextField(10)); p.add(new JTextField(10)); p.add(new JTextField(10)); p.add(new JTextField(10)); Set<AWTKeyStroke> set = p.getFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); //set = new HashSet(set); KeyStroke up = KeyStroke.getKeyStroke("A"); set.add(up);/*from ww w . ja v a 2 s .c o m*/ System.out.println(set); p.setFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, set); aWindow.add(p); aWindow.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JComponent button = new JButton("Cut"); String tooltiptext = "<html>" + "This is the " + "<img src=\"file:cut.gif\">" + " tool tip text." + "</html>"; button.setToolTipText(tooltiptext);//from w ww . j a v a2 s . c o m JPanel panel = new JPanel(); panel.add(button); frame.add(panel, BorderLayout.CENTER); frame.setSize(400, 400); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public static void main(String[] args) { JFrame fr = new JFrame(); JPanel p = new JPanel(); p.setLayout(new BorderLayout()); String[] ss = new String[] { "112", "1223", "1124", "1134" }; fr.getContentPane().add(p);/* ww w .jav a 2 s. c om*/ AutoCompleteComboBox cb = new AutoCompleteComboBox(ss); p.add("South", cb); p.add("Center", new JButton("test combo box")); fr.pack(); fr.setVisible(true); }