List of usage examples for javax.swing JPanel setLayout
public void setLayout(LayoutManager mgr)
From source file:Main.java
public Main() { setSize(350, 100);//from w w w.j a va 2 s .co m setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); bar.addAdjustmentListener(this); JPanel pane = new JPanel(); pane.setLayout(new BorderLayout()); pane.add(bar, "South"); setContentPane(pane); }
From source file:Main.java
public Main() throws Exception { setSize(400, 240);//from ww w. j a v a 2 s . co m JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); getContentPane().add(topPanel, BorderLayout.CENTER); RTFEditorKit rtf = new RTFEditorKit(); JEditorPane editor = new JEditorPane(); editor.setEditorKit(rtf); JScrollPane scroller = new JScrollPane(); scroller.getViewport().add(editor); topPanel.add(scroller, BorderLayout.CENTER); FileInputStream fi = new FileInputStream("test.rtf"); rtf.read(fi, editor.getDocument(), 0); }
From source file:CombinedLayoutManager.java
protected JComponent getButtonPanel() { JPanel inner = new JPanel(); inner.setLayout(new GridLayout(1, 2, 10, 0)); inner.add(new JButton("Ok")); inner.add(new JButton("Cancel")); return inner; }
From source file:Main.java
public JPanel createUI() { intro.setLabelFor(name);/* ww w .j av a2s . c o m*/ final JButton button = new JButton("Pick a new name..."); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20)); intro.setAlignmentX(JComponent.CENTER_ALIGNMENT); name.setAlignmentX(JComponent.CENTER_ALIGNMENT); button.setAlignmentX(JComponent.CENTER_ALIGNMENT); panel.add(intro); panel.add(Box.createVerticalStrut(5)); panel.add(name); panel.add(Box.createRigidArea(new Dimension(150, 10))); panel.add(button); return panel; }
From source file:MainClass.java
public MainClass() { setLayout(new BorderLayout()); JPanel jp = new JPanel(); jp.setLayout(new GridLayout(20, 20)); int b = 0;/*from w w w .j ava 2s . co m*/ for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { jp.add(new JButton("Button " + b)); ++b; } } // Add panel to a scroll pane. int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new JScrollPane(jp, v, h); // Add scroll pane to the content pane. add(jsp, BorderLayout.CENTER); }
From source file:Main.java
Main() { Object[][] data = { { "A", "B", "Snowboarding", new Integer(5) }, { "C", "D", "Pool", new Integer(10) } }; Object[] columnNames = { "firstname", "lastname", "age" }; final JTable table = new JTable(data, columnNames) { @Override//from w ww .jav a 2 s .c o m public Dimension getPreferredScrollableViewportSize() { Dimension d = getPreferredSize(); int n = getRowHeight(); return new Dimension(d.width, (n * ROWS)); } }; JPanel jPanel = new JPanel(); jPanel.setLayout(new GridLayout()); JScrollPane sp = new JScrollPane(table); jPanel.add(sp); JDialog jdialog = new JDialog(); jdialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); jdialog.setContentPane(jPanel); jdialog.pack(); jdialog.setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(400, 400);//from w ww . j a v a 2 s . co m JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split.setDividerLocation(200); add(split); JPanel panel1 = new JPanel(); panel1.setLayout(new BorderLayout()); panel1.add(new JLabel("top panel"), BorderLayout.NORTH); JPanel myDrawPanel = new JPanel(); myDrawPanel.setPreferredSize(new Dimension(100, 100)); myDrawPanel.add(new JLabel("draw panel here!")); panel1.add(new JScrollPane(myDrawPanel), BorderLayout.CENTER); split.setTopComponent(panel1); JPanel panel2 = new JPanel(); panel2.add(new JLabel("bottom panel")); split.setBottomComponent(panel2); setVisible(true); }
From source file:Main.java
Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(900, 600);//from ww w. ja v a 2 s . c om JPanel left = new JPanel(); left.setBackground(Color.BLUE); JPanel right = new JPanel(new BorderLayout()); JLabel fox = new JLabel("The quick brown fox jumps over the lazy dog."); fox.setFont(new Font(null, 0, 50)); JPanel rightBottom = new JPanel(); rightBottom.setLayout(new GridLayout(10, 10)); for (int i = 1; i <= 100; i++) { rightBottom.add(new JButton("butt" + i)); } right.add(fox, BorderLayout.NORTH); right.add(rightBottom, BorderLayout.CENTER); add(right); }
From source file:Main.java
public Main() { JPanel textPanel = new JPanel(); textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.PAGE_AXIS)); firstTextArea = new JTextArea(10, 50); secondTextArea = new JTextArea(10, 50); textPanel.add(new JScrollPane(firstTextArea)); textPanel.add(new JScrollPane(secondTextArea)); testFrame.add(textPanel, BorderLayout.CENTER); copyTextButton = new JButton("Copy text"); copyTextButton.addActionListener(e -> copyText()); testFrame.add(copyTextButton, BorderLayout.SOUTH); }
From source file:Main.java
public TabPanel() { JPanel innerPanel = new JPanel(); innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.Y_AXIS)); int USER_INPUT = 10; for (int i = 0; i < USER_INPUT; i++) { JPanel p = new JPanel(new BorderLayout()); JLabel label = new JLabel("Label" + i); JTextField textArea = new JTextField(); p.add(label, BorderLayout.NORTH); p.add(textArea, BorderLayout.CENTER); innerPanel.add(p);/*from w w w. j a va 2 s . co m*/ } JScrollPane scrollPane = new JScrollPane(innerPanel); scrollPane.setPreferredSize(new Dimension(400, 200)); this.add(scrollPane); }