是的,我GOOGLE了大约30分钟。是的,在stackoverflow中有关于该主题的2个不同的帖子,但那些不会给我任何解决我的问题。BoxLayout无法共享
我用了很多BoxLayout来定位一些东西。当我尝试添加最后的东西到我的主面板时,我得到“BoxLayout不能共享”。
代码:
private void open(int i) {
JLabel titelLabel = new JLabel("Aufgabenblatttitel: ");
JTextField titelTextField = new JTextField();
JLabel dozentLabel = new JLabel("Dozent: ");
JTextField dozentTextField = new JTextField();
JLabel beschreibungLabel = new JLabel("Aufgabenblattbeschreibung: ");
JTextField beschreibungTextField = new JTextField();
JLabel studiengangLabel = new JLabel("Studiengang: ");
JTextField studiengangTextField = new JTextField();
JLabel dateLabel = new JLabel("Erstellt am: ");
for(Aufgabe aufgabe : data.get(i).getAufgaben()) {
JPanel aufgabenPanel = new JPanel();
JLabel aufgabeTitelLabel = new JLabel("Titel: ");
JTextField aufgabeTitelTextField = new JTextField();
aufgabeTitelTextField.setText(aufgabe.getTitel());
JPanel aufgabeTitelPanel = new JPanel();
aufgabeTitelPanel.add(aufgabeTitelLabel);
aufgabeTitelPanel.add(aufgabeTitelTextField);
aufgabeTitelPanel.setLayout(new BoxLayout(aufgabeTitelPanel, BoxLayout.LINE_AXIS));
JLabel aufgabeBeschreibungLabel = new JLabel("Beschreibung: ");
JTextField aufgabeBeschreibungTextField = new JTextField();
aufgabeBeschreibungTextField.setText(aufgabe.getBeschreibung());
JPanel aufgabeBeschreibungPanel = new JPanel();
aufgabeBeschreibungPanel.add(aufgabeBeschreibungLabel);
aufgabeBeschreibungPanel.add(aufgabeBeschreibungTextField);
aufgabeBeschreibungPanel.setLayout(new BoxLayout(aufgabeBeschreibungLabel, BoxLayout.LINE_AXIS));
JLabel aufgabeLoesungLabel = new JLabel("Lösung: ");
JTextField aufgabeLoesungTextField = new JTextField();
aufgabeLoesungTextField.setText(aufgabe.getLoesung());
JPanel aufgabeLoesungPanel = new JPanel();
aufgabeLoesungPanel.add(aufgabeLoesungLabel);
aufgabeLoesungPanel.add(aufgabeLoesungTextField);
aufgabeLoesungPanel.setLayout(new BoxLayout(aufgabeLoesungPanel, BoxLayout.LINE_AXIS));
aufgabenPanel.add(aufgabeTitelPanel);
aufgabenPanel.add(aufgabeBeschreibungPanel);
aufgabenPanel.add(aufgabeLoesungPanel);
aufgabenPanel.setLayout(new BoxLayout(aufgabenPanel, BoxLayout.PAGE_AXIS));
this.add(aufgabenPanel);
}
}
这是类 “AufgabeEditieren”,这被定义为部分:
public class AufgabeEditieren extends JPanel { ... }
所以说:AufgabeEditieren构造函数调用open()类已经被初始化之后。它试图创建一些面板和对象,并希望通过“this.add(aufgabenPanel);”将它们添加到类本身。这是参考AufgabeEditieren(它的对象)。那为什么它不起作用?它的面板,应该能够得到这些物品?谢谢...
谢谢!当我太累时,我应该停止编码。像这样愚蠢的东西不得不躺在身边。 – Shiuyin 2014-10-29 20:51:11