2014-10-06 3 views
0

나는이 코드를 가지고있다. (예, 나는 초보자이다.)하지만 JTable은 보여주지 않는다. 패널을 만들기 전에 (아직 데이터 모델을 만들지 않았기 때문에) 마젠타 상자를 볼 수있었습니다.JTable이 보이지 않는 이유는 무엇입니까?

그러나 패널을 추가 한 후, 그것은 사라졌습니다. 아무도 그 이유를 말할 수 있습니까?. 미리 감사드립니다.

public Ost() { 
    super(); 
    JTable table; 
    OstBridge bridge; 
    JButton btn; 
    JPanel p1=new JPanel(new FlowLayout()); 
    JPanel p2=new JPanel(new FlowLayout()); 
    Container cp=getContentPane(); 
    cp.setLayout(new BoxLayout(cp,BoxLayout.Y_AXIS)); 




    p1.setBorder(BorderFactory.createTitledBorder("Panel 1")); 
    p2.setBorder(BorderFactory.createTitledBorder("Panel 2")); 
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); 
    this.setSize(320, 240); 
    this.setTitle("OST - Downloader"); 
    //this.setLayout(new FlowLayout()); 

    cp.add(p1); 
    cp.add(p2); 

    table=new JTable(); 
    table.setBackground(new Color(0xFF00FF)); 
    table.setSize(100, 100); 
    table.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); 
    p2.add(table); 

    bridge=new OstBridge(); 

    btn=new JButton("Prueba"); 
    btn.addActionListener(new ActionListener() { 

     @Override 
     public void actionPerformed(ActionEvent e) { 
      // TODO Auto-generated method stub 
      System.out.println("Action event"); 
      System.out.println(e); 
      System.out.println(bridge); 
      new Ost(); 

     } 
    }); 

    p1.add(btn); 
    p1.setVisible(true); 
    this.pack(); 

    this.setVisible(true); 
} 

답변

1

흥미로운 것을보기 위해 데이터 및/또는 데이터 모델이 필요합니다.

당신과 같이 JScrollPane의 내부에 테이블을 추가하는 경우 :

p2.add(new JScrollPane(table)); 

당신이 적어도 구성 요소의 개요를 볼 수 있습니다.

관련 문제