Hi. In my attempts to create an email client, netbean's GUI builder has made me very unhappy... so, I decided I'd rather code it by hand... not my best idea, but whatever. Now, I'm trying to nest a Vertical JSplitPane in a Horizontal JSplitPane, and I can't see the left side of the Pane that is split down the middle. When I run the program, I only see the handle for the bar that resizes up and down... I want it to look something like this, I got it to work in the GUI builder, but I've stopped using that...:
__________
| | |
| | |
| +-------|
| | |
|_|_______|
where the lines that intersect the + can be moved.
Also, the GridBagLayout is starting at the top left corner, but in the center... does anyone know how to fix that????
Here's my code:
lines 79-99 are the problem area for the JSplitPanes i believe
package JEmail;
import javax.swing.*;
import java.awt.*;
/**
* Write a description of class JMail_Runner here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class JMail_Runner{
private static final int PWIDTH = 600;
private static final int PHEIGHT = 500;
static JFrame jMailWindow;
public static void createAndShowGUI(){
// try{ // Set the L&F to match the System - will have option to change later.
// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// }catch(Exception e){
// e.printStackTrace();
// }
GridBagConstraints c = new GridBagConstraints();
jMailWindow = new JFrame("JEmail");
Container contentPane = jMailWindow.getContentPane();
contentPane.setLayout(new GridBagLayout());
jMailWindow.setPreferredSize(new Dimension(PWIDTH, PHEIGHT));
jMailWindow.setLocation(150,100);
jMailWindow.setVisible(true);
jMailWindow.setSize(PWIDTH, PHEIGHT);
/**
* Init the JMenuBar and add JMenus
*/
WindowComponents.menuBar = new JMenuBar();
WindowComponents.file = new JMenu("File");
WindowComponents.edit = new JMenu("Edit");
WindowComponents.mail = new JMenu("Mail");
WindowComponents.help = new JMenu("Help");
WindowComponents.menuBar.add(WindowComponents.file);
WindowComponents.menuBar.add(WindowComponents.edit);
WindowComponents.menuBar.add(WindowComponents.mail);
WindowComponents.menuBar.add(WindowComponents.help);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.5;
contentPane.add(WindowComponents.menuBar, c);
/**
* Init the JToolBar and add JComponents
*/
WindowComponents.toolBar = new JToolBar();
WindowComponents.previous = new JButton(" < ");
WindowComponents.next = new JButton(" > ");
WindowComponents.compose = new JButton("Compose Mail");
WindowComponents.check = new JButton("Check Mail");
WindowComponents.searchField = new JTextField("Enter Search Term", 30);
WindowComponents.toolBar.add(WindowComponents.previous);
WindowComponents.toolBar.add(WindowComponents.next);
WindowComponents.toolBar.addSeparator();
WindowComponents.toolBar.add(WindowComponents.check);
WindowComponents.toolBar.add(WindowComponents.compose);
WindowComponents.toolBar.addSeparator();
WindowComponents.toolBar.add(WindowComponents.searchField);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 1;
c.weightx = 0.5;
c.gridwidth = 1;
contentPane.add(WindowComponents.toolBar, c);
/**
* Init the JSplitPanes and add them to the JFrame
*/
WindowComponents.vertical = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
WindowComponents.horizontal = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
WindowComponents.tabs = new JTabbedPane();
WindowComponents.files = new JTree();
WindowComponents.horizontal.setLeftComponent(WindowComponents.files);
WindowComponents.horizontal.setRightComponent(WindowComponents.vertical);
WindowComponents.vertical.setTopComponent(WindowComponents.tabs);
WindowComponents.vertical.setBottomComponent(new JPanel());
WindowComponents.horizontal.setDividerLocation(.5);
WindowComponents.vertical.setDividerLocation(.5);
WindowComponents.tabs.setPreferredSize(new Dimension(400, 250));
WindowComponents.tabs.setSize(WindowComponents.tabs.getPreferredSize());
WindowComponents.tabs.add(new JPanel(), "Test");
c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
c.gridy = 2;
c.weightx = 1.0;
c.gridwidth = 1;
c.gridheight = GridBagConstraints.REMAINDER; //make this component tall
contentPane.add(WindowComponents.vertical, c);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
package JEmail;
/**
* This class is comprised of a list of pre-init static
* JComponents. These components make up the GUI of the
* JEmail program. This class has only static values so
* if one operation changes a menu/component, there is no
* confliction with other operations. If there is a confliction,
* it will be dealt with else-where. (Possibly here, I haven't
* decided yet...)
*/
/**
* NOTES TO ME / TO DO:
* Add another JPanel for the notesScrollPane's contents
*/
import javax.swing.*;
import JEmail.util.*;
public class WindowComponents{
// Components for the JEmail Window
public static JMenuBar menuBar;
public static JMenu file, edit, mail, help;
public static JSplitPane vertical, horizontal;
public static JTabbedPane tabs;
public static JTree files;
public static JPanel mailPanel, contactsPanel, notesPanel, inboxPanel;
public static JScrollPane inboxScrollPane, notesScrollPane, contentsScrollPane,
contactsPane;
// public static InboxHeader inboxHeader;
// for organizing/visualizing contacts
// public static ContactsHeader contactsHeader;
// JToolBar and components
public static JToolBar toolBar;
public static JButton next, previous, compose, check;
public static JTextField searchField;
}