blackfrancis75
asked on
problem with BorderLayout
How can I make 'panel' (in the center ) stretch vertically and horizontally to fill the complete space in between the North and South areas of the BorderLayout?
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTree;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
public class Main extends JFrame {
private static final long serialVersionUID = -573737534454859870L;
private JPanel contentPane;
private JPanel northPanel;
private JButton btnNew;
private JButton btnOpen;
private JButton btnSave;
private JPanel southPanel;
private JLabel statusLabel;
private JTree tree = null;
private JTabbedPane tabbedPane = null;
private JSplitPane splitPane;
private JScrollPane scrollPane;
private JScrollPane scrollPane_1;
private JTextArea textArea;
private JTable table = null;
private JScrollPane scrollPane_2;
private JSplitPane centerSplit;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 750, 500);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(1, 1));
setContentPane(contentPane);
northPanel = new JPanel();
northPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
contentPane.add(northPanel, BorderLayout.NORTH);
btnNew = new JButton("New");
northPanel.add(btnNew);
btnOpen = new JButton("Open");
northPanel.add(btnOpen);
btnSave = new JButton("Save");
northPanel.add(btnSave);
southPanel = new JPanel();
southPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
contentPane.add(southPanel, BorderLayout.SOUTH);
tabbedPane = new JTabbedPane();
centerSplit = new JSplitPane();
JPanel panel = new JPanel();
panel.add(centerSplit);
contentPane.add(panel, BorderLayout.CENTER);
splitPane = new JSplitPane();
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
tabbedPane.addTab("New tab", null, splitPane, null);
scrollPane = new JScrollPane();
splitPane.setLeftComponent(scrollPane);
textArea = new JTextArea();
textArea.setPreferredSize(new Dimension(600,200));
scrollPane.setViewportView(textArea);
scrollPane_1 = new JScrollPane();
splitPane.setRightComponent(scrollPane_1);
table = new JTable();
scrollPane_1.setViewportView(table);
statusLabel = new JLabel("");
southPanel.add(statusLabel);
scrollPane_2 = new JScrollPane();
centerSplit.setLeftComponent(scrollPane_2);
centerSplit.setRightComponent(tabbedPane);
tree = new JTree();
tree.setPreferredSize(new Dimension(100,200));
scrollPane_2.setViewportView(tree);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
thanx 4 axxepting