Hallo ersteinmal,
also ich habe ein Dialog mit einer JList.
Nun möchte ich in dieser Liste einige Sachen markieren und beim klick auf den "OK" Button soll das ganze dann an das Hauptfenster übergeben werden.
Leider bekomme ich diese Fehlermeldung: The final local variable listIndex cannot be assigned, since it is defined in an enclosing type
also ich habe ein Dialog mit einer JList.
Nun möchte ich in dieser Liste einige Sachen markieren und beim klick auf den "OK" Button soll das ganze dann an das Hauptfenster übergeben werden.
Leider bekomme ich diese Fehlermeldung: The final local variable listIndex cannot be assigned, since it is defined in an enclosing type
Code:
public Object[] searchDialog()
{
GridBagLayout gbl = new GridBagLayout();
final JDialog psDialog = new JDialog();
final Object[] listIndex = null;
Container c = psDialog.getContentPane();
c.setLayout(gbl);
JPanel north = new JPanel();
north.setLayout(gbl);
north.setBorder( new SoftBevelBorder(SoftBevelBorder.RAISED) );
JPanel south = new JPanel();
south.setLayout(gbl);
south.setBorder( new SoftBevelBorder(SoftBevelBorder.RAISED) );
JLabel lProcessStep = new JLabel(" ProcessStep ", JLabel.CENTER);
addComponent( north, gbl, lProcessStep, 1, 1, 1, 1, 1, 1);
final JTextField textFieldSearchProcessStep = new JTextField();
addComponent( north, gbl, textFieldSearchProcessStep, 2, 1, 2, 1, 1, 10);
final JList listProcessStep = new JList(new ProcessStep().getAllProcessStep());
listProcessStep.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
listProcessStep.setFixedCellHeight(20);
JScrollPane scrollProcessStep = new JScrollPane(listProcessStep);
listProcessStep.setBorder( new SoftBevelBorder(SoftBevelBorder.RAISED) );
final JButton buttonOK = new JButton("OK");
addComponent( south, gbl, buttonOK, 1, 1, 1, 1, 1, 1);
final JButton buttonCancel = new JButton("Cancel");
addComponent( south, gbl, buttonCancel, 2, 1, 1, 1, 1, 1);
addComponent( c, gbl, north, 1, 1, 1, 1, 1, 1);
addComponent( c, gbl, scrollProcessStep, 1, 2, 1, 1, 1, 50);
addComponent( c, gbl, south, 1, 3, 1, 1, 1, 1);
textFieldSearchProcessStep.addKeyListener(new KeyAdapter()
{
public void keyReleased(KeyEvent e)
{
Vector v = new ProcessStep().getAllProcessStepWith((String)textFieldSearchProcessStep.getText());
listProcessStep.setListData(v);
}
});
buttonOK.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
listIndex = listProcessStep.getSelectedValues();
}
});
buttonCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
psDialog.setVisible(false);
}
});
psDialog.setModal(true);
psDialog.setLocation(350, 150);
psDialog.setSize(300, 400);
psDialog.setResizable(false);
psDialog.setVisible(true);
return listIndex;
}
}