我想在一个JFrame 中放入一个JPanel
JFrame 的布局是borderlayout
JPanel 的布局是null,
我把JPanel入在JFrame中为什么不能显示.....
谁能给我一个例子代码

解决方案 »

  1.   

    我这个里面用到了布局管理器,不过稍微长了点,你就看看构造方法吧:统计Java源文件的代码行
      

  2.   

    add(panel,BorderLayout.NORTH);    like  this??
      

  3.   

    順便說句  這個panel  你不加效果    就是add上了  你也看不出來是加上了~~
      

  4.   

    确实是这样,你应该在panel上加个组件再试试
    panel上面没有东西,是看不出效果的
      

  5.   

    this.setVisiable(true);设置可见
    add(panel);
    我想了下 ,你的错误有两个地方:1,没有把frame设置可见 2,如果第一个没错 那就可能是没有把panel添加到frame中。
    前提是你代码没有写错!
    其实  不显示也就和这两个地方有关。
    给分
      

  6.   

    程序如下...jpanel加到JFrame中不能显示...jpanel的布局是null,,,去掉jpanle的null布启就可以显示...这是为什么,,但是我想让panel的布局是null形式的
    import java.awt.*;
    import java.awt.event.*;
    import javax.comm.*;import javax.swing.*;
    import javax.swing.border.*;
    public class d extends JFrame{
        
        
       
        JPanel p = new JPanel();    //存放工具设置的
        
        private JButton b1 = new JButton("Setup");
        private JButton b2 = new JButton("Close");
        public JLabel l1 = new JLabel("lcd");    
        private String marstr="not connect,please Setup"; 
     
        public int x=0;
        public  int y=44;
        Graphics gg;    
        public Timer tme1;
        public Timer tme2;
        public int speed = 10;
        public int screenw = 340;
        public int screenh = 90;
        
        public int screensize = 2;
        
        public d(){
            Container con = this.getContentPane(); con.setLayout(new BorderLayout());      p.setBackground(Color.darkGray);
          p.setLayout(null);
          
          
            b1.setBounds(340, 0, 60, 40);
            b1.setBackground(Color.BLACK);
            b1.setForeground(Color.WHITE);
            b1.setBorder(null);
            
            
            
            b2.setBounds(280, 0, 60, 40);
            b2.setBackground(Color.BLACK);
            b2.setForeground(Color.WHITE);
            b2.setBorder(null);
            
            l1.setBounds(200, 0, 90, 60);
            l1.setBackground(Color.BLACK);
            l1.setForeground(Color.WHITE);
            l1.setBorder(null);
            
            
            p.add(b1);
            p.add(b2);
           con.add(p,BorderLayout.SOUTH);
           con.add(l1,BorderLayout.EAST);
           con.setBackground(Color.WHITE);
            this.setSize(screenw,screenh);    
            this.setTitle("LCD   not connect!!");
            this.setResizable(false);           
            this.setVisible(true);        
            
        }
        
        public void paint(Graphics g){
            super.paint(g);
            
            g.setColor(Color.RED);
            g.drawString("sdf", x,y);
       
            
        }        public static void main(String args[]){
           
            d lc= new d();  
            
        }
        }