java中点击一个按钮新建一个新的JPanel并显示出来可以吗,在线等急。。。 10
publicclassMyPanLeftextendsJPanelimplementsActionListener{privateJPanelmyPanel;privat...
public class MyPanLeft extends JPanel implements ActionListener
{
private JPanel myPanel;
private JButton ok3;
JPanel leftPanel =null;
public MyPanLeft()
{
ok3 = new JButton("sss");
ok3.addActionListener(this);
leftPanel = new JPanel(new GridLayout(12,2));
leftPanel.add(doubleLB3);
leftPanel.add(ok3);
leftPanel.setBorder(BorderFactory.createTitledBorder("kkkk"));
leftPanel.setSize(250,480);
PlaneModel planeModel = new PlaneModel();
planeTable = new JTable(planeModel);
planeTable.setRowHeight(35);
planeScrollPane = new JScrollPane(planeTable);
planeScrollPane.setPreferredSize(new Dimension(780, 480));
// 添
leftPanel.setBounds(0, 0, 200, 480);
this.setLayout(null);
this.add(leftPanel);
this.setSize(200, 480);
this.setVisible(true);
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
if(e.getSource() == ok3)
{
myPanel = new MyPanel();
this.add(myPanel);
myPanel.setVisible(true);
}
}
}
这样写点击ok3,始终myPanel显示不出来,求高手指点,希望把可编译代码贴出来谢谢了 展开
{
private JPanel myPanel;
private JButton ok3;
JPanel leftPanel =null;
public MyPanLeft()
{
ok3 = new JButton("sss");
ok3.addActionListener(this);
leftPanel = new JPanel(new GridLayout(12,2));
leftPanel.add(doubleLB3);
leftPanel.add(ok3);
leftPanel.setBorder(BorderFactory.createTitledBorder("kkkk"));
leftPanel.setSize(250,480);
PlaneModel planeModel = new PlaneModel();
planeTable = new JTable(planeModel);
planeTable.setRowHeight(35);
planeScrollPane = new JScrollPane(planeTable);
planeScrollPane.setPreferredSize(new Dimension(780, 480));
// 添
leftPanel.setBounds(0, 0, 200, 480);
this.setLayout(null);
this.add(leftPanel);
this.setSize(200, 480);
this.setVisible(true);
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
if(e.getSource() == ok3)
{
myPanel = new MyPanel();
this.add(myPanel);
myPanel.setVisible(true);
}
}
}
这样写点击ok3,始终myPanel显示不出来,求高手指点,希望把可编译代码贴出来谢谢了 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询