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) { JTabbedPane tp = new JTabbedPane(); tp.addTab("Dates", new JPanel()); tp.addTab("Deliveries", new JPanel()); tp.addTab("Exports", new JPanel()); tp.setTabComponentAt(0, new JLabel("Dates")); tp.setTabComponentAt(1, new JLabel("Deliveries")); tp.setTabComponentAt(2, new JLabel("Exports")); JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(tp);//from w w w .j a v a 2 s.c o m frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout);//from w ww .j a v a 2 s . com JButton buttonD = new JButton("D"); JButton buttonR = new JButton("R"); JButton buttonY = new JButton("Y"); JButton buttonO = new JButton("O"); JButton buttonT = new JButton("T"); GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup(); leftToRight.addComponent(buttonD); GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup(); columnMiddle.addComponent(buttonR); columnMiddle.addComponent(buttonO); columnMiddle.addComponent(buttonT); leftToRight.addGroup(columnMiddle); leftToRight.addComponent(buttonY); GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup(); GroupLayout.ParallelGroup rowTop = layout.createParallelGroup(); rowTop.addComponent(buttonD); rowTop.addComponent(buttonR); rowTop.addComponent(buttonY); topToBottom.addGroup(rowTop); topToBottom.addComponent(buttonO); topToBottom.addComponent(buttonT); layout.setHorizontalGroup(leftToRight); layout.setVerticalGroup(topToBottom); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(800, 600)); String test[] = { "alpha", "bravo", "charlie", "delta", "echo", "omega", "zeta" }; JList<String> list = new JList<>(test); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setLayoutOrientation(JList.VERTICAL); list.setVisibleRowCount(5);//from w w w .j av a 2s . c o m list.setBounds(50, 150, 75, 90); JScrollPane jScrollPane1 = new JScrollPane(); jScrollPane1.setViewportView(list); panel.add(jScrollPane1); JFrame f = new JFrame(); f.add(panel); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setResizable(false); f.setFocusable(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.setLayout(new OverlayLayout(panel)); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.add("1", new JTextField("one")); tabbedPane.add("2", new JTextField("two")); tabbedPane.setAlignmentX(1.0f);// w ww . j a v a 2 s . c o m tabbedPane.setAlignmentY(0.0f); JCheckBox checkBox = new JCheckBox("Add tab"); checkBox.setOpaque(false); checkBox.setAlignmentX(1.0f); checkBox.setAlignmentY(0.0f); panel.add(checkBox); panel.add(tabbedPane); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.setSize(400, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout);// ww w.j a v a 2 s. c o m System.out.println(layout.getLayoutStyle()); JButton buttonD = new JButton("D"); JButton buttonR = new JButton("R"); JButton buttonY = new JButton("Y"); JButton buttonO = new JButton("O"); JButton buttonT = new JButton("T"); GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup(); leftToRight.addComponent(buttonD); GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup(); columnMiddle.addComponent(buttonR); columnMiddle.addComponent(buttonO); columnMiddle.addComponent(buttonT); leftToRight.addGroup(columnMiddle); leftToRight.addComponent(buttonY); GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup(); GroupLayout.ParallelGroup rowTop = layout.createParallelGroup(); rowTop.addComponent(buttonD); rowTop.addComponent(buttonR); rowTop.addComponent(buttonY); topToBottom.addGroup(rowTop); topToBottom.addComponent(buttonO); topToBottom.addComponent(buttonT); layout.setHorizontalGroup(leftToRight); layout.setVerticalGroup(topToBottom); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel bottomPanel = new JPanel(); bottomPanel.add(new JButton("Bottom Button")); bottomPanel.setBorder(BorderFactory.createTitledBorder("Bottom Panel")); JPanel centerPanel = new JPanel(); centerPanel.setBorder(BorderFactory.createTitledBorder("Center Panel")); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(centerPanel, BorderLayout.CENTER); mainPanel.add(bottomPanel, BorderLayout.PAGE_END); int eb = 25;//from w w w . j a va2 s. co m mainPanel.setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb)); mainPanel.setPreferredSize(new Dimension(500, 400)); JFrame frame = new JFrame("Main"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout);/*from ww w. jav a 2 s .c o m*/ System.out.println(layout.getAutoCreateGaps()); JButton buttonD = new JButton("D"); JButton buttonR = new JButton("R"); JButton buttonY = new JButton("Y"); JButton buttonO = new JButton("O"); JButton buttonT = new JButton("T"); GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup(); leftToRight.addComponent(buttonD); GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup(); columnMiddle.addComponent(buttonR); columnMiddle.addComponent(buttonO); columnMiddle.addComponent(buttonT); leftToRight.addGroup(columnMiddle); leftToRight.addComponent(buttonY); GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup(); GroupLayout.ParallelGroup rowTop = layout.createParallelGroup(); rowTop.addComponent(buttonD); rowTop.addComponent(buttonR); rowTop.addComponent(buttonY); topToBottom.addGroup(rowTop); topToBottom.addComponent(buttonO); topToBottom.addComponent(buttonT); layout.setHorizontalGroup(leftToRight); layout.setVerticalGroup(topToBottom); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); panel.add(new JTextField(10)); panel.add(new JButton("button")); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel);//from www . j a v a 2 s. c o m frame.pack(); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { @Override public void windowIconified(WindowEvent wEvt) { ((JFrame) wEvt.getSource()).dispose(); } @Override public void windowDeactivated(WindowEvent wEvt) { ((JFrame) wEvt.getSource()).dispose(); } }); }
From source file:Main.java
public static void main(String[] args) { Object[] options1 = { "Try This Number", "Choose A Random Number", "Quit" }; JPanel panel = new JPanel(); panel.add(new JLabel("Enter number between 0 and 1000")); JTextField textField = new JTextField(10); panel.add(textField);/*from ww w . j a v a2s.com*/ int result = JOptionPane.showOptionDialog(null, panel, "Enter a Number", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options1, null); if (result == JOptionPane.YES_OPTION) { JOptionPane.showMessageDialog(null, textField.getText()); } }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout);//from ww w.j ava 2 s .c o m System.out.println(layout.getHonorsVisibility()); JButton buttonD = new JButton("D"); JButton buttonR = new JButton("R"); JButton buttonY = new JButton("Y"); JButton buttonO = new JButton("O"); JButton buttonT = new JButton("T"); GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup(); leftToRight.addComponent(buttonD); GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup(); columnMiddle.addComponent(buttonR); columnMiddle.addComponent(buttonO); columnMiddle.addComponent(buttonT); leftToRight.addGroup(columnMiddle); leftToRight.addComponent(buttonY); GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup(); GroupLayout.ParallelGroup rowTop = layout.createParallelGroup(); rowTop.addComponent(buttonD); rowTop.addComponent(buttonR); rowTop.addComponent(buttonY); topToBottom.addGroup(rowTop); topToBottom.addComponent(buttonO); topToBottom.addComponent(buttonT); layout.setHorizontalGroup(leftToRight); layout.setVerticalGroup(topToBottom); frame.add(panel); frame.pack(); frame.setVisible(true); }