Some background: I am making a program that uses a JTree full of nodes of various types. The TreeSelectionListener determines what type of node it is, clears an inner JPanel of components, then adds the appropriate JPanel to the JPanel it just cleared, to edit properties specific to that type of node. The JPanel uses GridBagLayout, but the text fields aren't displaying correctly (Note: the title is a JTextField, the description is a JTextArea:
Code for the JPanel is as follows:
class nodePanel extends JPanel{
public nodePanel(DefaultMutableTreeNode info){
super(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets=new Insets(10,10,10,10);
c.gridx=0;
c.gridy=0;
c.gridheight=1;
c.gridwidth=1;
c.weightx=0;
c.weighty=0;
c.fill=GridBagConstraints.NONE;
c.anchor=GridBagConstraints.EAST;
this.add(new JLabel("Title: "),c);
c.gridy=1;
c.weighty=2;
c.gridheight=2;
this.add(new JLabel("Description: "),c);
c.gridx=1;
c.gridy=0;
c.gridheight=1;
c.gridwidth=2;
c.weightx=100;
c.weighty=0;
c.anchor=GridBagConstraints.WEST;
c.fill=GridBagConstraints.HORIZONTAL;
JTextField title = new JTextField();
title.setMinimumSize(new Dimension(300,25));
this.add(title,c);
c.gridy=1;
c.gridheight=2;
c.weighty=200;
JTextArea description = new JTextArea();
JScrollPane descriptionScroll= new JScrollPane(description);
descriptionScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
descriptionScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
this.add(descriptionScroll, c);
}
}
Thank you