Hallo,
ich möchte gern ein Step-By-Step realisieren. Dafür habe ich ein Panel, auf dem der Benutzer eine Eingabe machen muss, entsprechend der Auswahl soll dann ein zweites Panel mit Eingabefelder geöffnet werden.
Mein Code bisher:
Mein erstes Panel wird angezeigt, aber das zweite nicht mehr, wenn ich das Panel gleich lade und verstecke und dann einfach anzeige, klappt es auch, aber wie zeige ich dann die Eingabefelder entsprechend der Auswahl in Step1 an. (Ich weiß das da im Moment nur 1 Element ist, aber später sind da insgesamt etwa 10 Textfelder und 5- 8 brauch ich nur, je nach Auswahl).
Vielen Dank für eure Hilfe
chrissy
ich möchte gern ein Step-By-Step realisieren. Dafür habe ich ein Panel, auf dem der Benutzer eine Eingabe machen muss, entsprechend der Auswahl soll dann ein zweites Panel mit Eingabefelder geöffnet werden.
Mein Code bisher:
Code:
private void showStep1()
{
pnlStep1.setVisible(true);
this.getContentPane().add(pnlStep1,
new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 100, 0));
GridBagLayout layoutInput = new GridBagLayout();
pnlStep1.setLayout(layoutInput);
JLabel lblStep1 = new JLabel("<html>[b]<u>Step 1</u>[/b]</html>");
JRadioButton opt1 = new JRadioButton("Option1");
opt1.setSelected(true);
JRadioButton opt2 = new JRadioButton("Option2");
ButtonGroup bgSelect = new ButtonGroup();
bgSelect.add(opt1);
bgSelect.add(opt2);
JButton btnNext = new JButton("Next >");
btnNext.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
pnlStep2.setVisible(true);
}
});
pnlStep1.add(lblStep1,
new GridBagConstraints(0, 0, 4, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0,0,10,0), 0, 0));
pnlStep1.add(opt1,
new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0,0,2,0), 0, 0));
pnlStep1.add(opt2,
new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0,0,2,0), 0, 0));
pnlStep1.add(btnNext,
new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0,0,2,0), 0, 0));
pnlStep1.setPreferredSize(new Dimension(100, 100));
}
private void showStep2()
{
pnlStep2.setVisible(true);
this.getContentPane().add(pnlStep2,
new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 100, 0));
GridBagLayout layoutInput = new GridBagLayout();
pnlStep2.setLayout(layoutInput);
String[] comboSelect = {"Case1", "Case2", "Case3", "Case4", "Case5"};
cboCase = new JComboBox(comboSelect);
JLabel lblStep2 = new JLabel("<html>[b]<u>Step 2</u>[/b]</html>");
pnlStep2.add(lblStep2,
new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0,0,20,0), 0, 0));
pnlStep2.add(cboCase, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 2, 0), 70, 0));
pnlStep2.setPreferredSize(new Dimension(100, 50));
}
Mein erstes Panel wird angezeigt, aber das zweite nicht mehr, wenn ich das Panel gleich lade und verstecke und dann einfach anzeige, klappt es auch, aber wie zeige ich dann die Eingabefelder entsprechend der Auswahl in Step1 an. (Ich weiß das da im Moment nur 1 Element ist, aber später sind da insgesamt etwa 10 Textfelder und 5- 8 brauch ich nur, je nach Auswahl).
Vielen Dank für eure Hilfe
chrissy