2014-01-13 4 views
-4

이 코드의 잘못된 점을 누군가에게 알려주시겠습니까? 메뉴를 제외하고는 아무 것도 보여주지 않아서 무엇이 잘못되었는지를 파악할 수 없습니다.JTable이 표시되지 않습니다

public class ProfesorSelect extends JFrame { 
    public ProfesorSelect(Profesor profesor){ 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     JMenuBar menuBar = new JMenuBar(); 
     JMenu fileMenu = new JMenu("File"); 
     JMenuItem newItem = new JMenuItem("Logout"); 
     JMenuItem open = new JMenuItem("Exit"); 
     setLayout(new GridBagLayout()); 
     GridBagConstraints constraints = new GridBagConstraints(); 
     constraints.anchor = GridBagConstraints.CENTER; 
     fileMenu.add(newItem); 
     fileMenu.add(open); 
     setName(profesor.toString() + " /Profesor"); 
     menuBar.add(fileMenu); 
     JScrollPane panel = new JScrollPane(); 
     JScrollPane scrollPanel = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 
     for(Clasa clasa: Centralizator.getInstance().getClase()){ 
      JPanel panelClasa = new JPanel(); 
      panelClasa.setLayout(new BoxLayout(panelClasa,BoxLayout.Y_AXIS)); 
      JLabel numeClasa = new JLabel(clasa.getIdClasa()); 
      ArrayList<String> elevi = new ArrayList<String>(); 
      for (Elev elev : clasa.getElevi()){ 
       elevi.add(elev.toString()); 
      } 
      JScrollPane jScrollPane = new JScrollPane(new JList(elevi.toArray())); 
      panelClasa.add(numeClasa); 
      panelClasa.add(jScrollPane); 
      scrollPanel.add(panelClasa); 
     } 
     add(scrollPanel); 

     setJMenuBar(menuBar); 
     pack(); 
     setVisible(true); 
    } 
} 
+5

를 살펴 보자. 이 코드는'main (String []) '을 필요로하고 MCVE로 임포트합니다. –

+6

젠장, 농담해라. 코드에 JTable조차 없다. 진심으로? 이 질문을 향상 시키거나 삭제하십시오. –

+0

'Centralizator' 물론 물론 클래스를 포함 시키거나 MCVE를 보여주기 위해 완전히 배제해야합니다. –

답변

2

사용하지 마십시오 scrollPane.add 이것은 스크롤 창을 사용하는 방법이 아닙니다.

빨리,이 [MCVE] (http://stackoverflow.com/help/mcve)를 게시 더 나은 도움말을 How to use scroll panes

관련 문제