L
linuxping
Unregistered / Unconfirmed
GUEST, unregistred user!
为何不见LeftPanel上的JTextArea?
import javax.swing.JFrame;
import java.awt.GridLayout;
import cpn.*;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f=new JFrame();
f.setJMenuBar(new MenuBar());
LeftPanel lp=new LeftPanel();
f.setLayout(new GridLayout(1,2) );
f.getContentPane().add(lp);
f.setSize(700,500);
f.setVisible(true);
}
}
========================
package cpn;
import java.awt.LayoutManager;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JTextArea;
import javax.swing.JTree;
import java.awt.Insets;
public class LeftPanel extends JPanel {
public static GridBagLayout gbl;
public LeftPanel() {
this.setLayout(gbl);
GridBagConstraints c=new GridBagConstraints();
c.anchor=GridBagConstraints.NORTH;
c.fill=GridBagConstraints.BOTH;
c.gridx=0;
c.gridy=0;
c.gridheight=1;
c.gridwidth=1;
c.weightx=0;
c.weighty=0;
JTextArea t=new JTextArea("test it");
this.add(t, c);
JTree tree=new JTree();
c.gridy++;
c.insets=new Insets(0,1,0,0);
this.add(tree,c);
}
public LeftPanel(LayoutManager layout) {
super(layout);
// TODO Auto-generated constructor stub
}
public static GridBagLayout getGbl() {
return gbl;
}
public static void setGbl(GridBagLayout gbl) {
LeftPanel.gbl = gbl;
}
}
import javax.swing.JFrame;
import java.awt.GridLayout;
import cpn.*;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f=new JFrame();
f.setJMenuBar(new MenuBar());
LeftPanel lp=new LeftPanel();
f.setLayout(new GridLayout(1,2) );
f.getContentPane().add(lp);
f.setSize(700,500);
f.setVisible(true);
}
}
========================
package cpn;
import java.awt.LayoutManager;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JTextArea;
import javax.swing.JTree;
import java.awt.Insets;
public class LeftPanel extends JPanel {
public static GridBagLayout gbl;
public LeftPanel() {
this.setLayout(gbl);
GridBagConstraints c=new GridBagConstraints();
c.anchor=GridBagConstraints.NORTH;
c.fill=GridBagConstraints.BOTH;
c.gridx=0;
c.gridy=0;
c.gridheight=1;
c.gridwidth=1;
c.weightx=0;
c.weighty=0;
JTextArea t=new JTextArea("test it");
this.add(t, c);
JTree tree=new JTree();
c.gridy++;
c.insets=new Insets(0,1,0,0);
this.add(tree,c);
}
public LeftPanel(LayoutManager layout) {
super(layout);
// TODO Auto-generated constructor stub
}
public static GridBagLayout getGbl() {
return gbl;
}
public static void setGbl(GridBagLayout gbl) {
LeftPanel.gbl = gbl;
}
}