【发布时间】:2014-02-01 15:53:27
【问题描述】:
谁能告诉我这段代码有什么问题?除了菜单,它没有显示任何内容,我似乎无法弄清楚出了什么问题。
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);
}
}
【问题讨论】:
-
如需尽快获得更好的帮助,请发布MCVE。代码需要
main(String[])并导入为 MCVE。 -
哎呀,你一定是在开玩笑吧,...你的代码甚至没有 JTable。严重地?请改进这个问题很多或删除它。
-
Centralizator当然,您需要包含该类,或者将其完全分解以显示 MCVE..
标签: java swing jtable jscrollpane