JOptionPane/Dialog
Hi!
I have a simple problem, I am trying to implement find feature, so this is what I am doing, I use a JOptionPane.showInputDialog().
Now this is my problem.
I want it to recursively search the entire tree, so after it finds the first one, it shud still be visible, and allow the user to do a find next, but the JOptionPane disappears after every clcik on "ok".
So I found a workaround by implementing a while loop which keeps showing the dialog until cancle is pressed, or end ot tree is reached.
BUT!!! the problem is that the text in the textfield is cleared, cos' everytime I create a new instance of the showDialogbox, and also since its a new instance the last position is not rem. so it creates one in the original position.
Is there a way by which I can
1. set the text in the inputfield on a JOptionPane
2. Create a single instance of the InputDialogBox of the JOptionPane, so that it rem. the position on the creen.
3. Change the labels on the button from OK and Cancle, to "FInd/Next and cancle
Any help/ideas will be greatly appreciated.
[1133 byte] By [
help_me1] at [2007-9-26 8:58:44]

I faced exactly this problem which i solved by extending the JOptionPane class and overridding its createDialog method. The code is given below:
String buttons[] = {
WPApp.resMenu.getString("Find_Next_Button"),
WPApp.resMenu.getString("Cancel")
};
//override the createDialog() method of the JOptionPane so that it
//does not dispose on pressing the Find Next Button button.
JOptionPane aPane = new JOptionPane(createMiddlePanel(), -1, JOptionPane.OK_CANCEL_OPTION, null, buttons, buttons[0])
{
public JDialog createDialog(Component parentComponent, String title)
{
final JDialog aDialog = new JDialog((Frame)parentComponent, title, true);;
Container contentPane = aDialog.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(this, BorderLayout.CENTER);
aDialog.pack();
aDialog.setLocationRelativeTo(parentComponent);
aDialog.addWindowListener(new WindowAdapter()
{
boolean gotFocus = false;
public void windowClosing(WindowEvent we)
{
setValue(null);
}
public void windowActivated(WindowEvent we)
{
// Once window gets focus, set initial focus
if (!gotFocus)
{
selectInitialValue();
gotFocus = true;
}
}
});
// don't uncomment this code
// this causes the JOptionPane NOT to disappear
//addPropertyChangeListener(new PropertyChangeListener()
//{
// public void propertyChange(PropertyChangeEvent event)
// {
// if(aDialog.isVisible() &&
//(event.getPropertyName().equals(VALUE_PROPERTY) ||
//event.getPropertyName().equals(INPUT_VALUE_PROPERTY)))
// {
//aDialog.setVisible(false);
//aDialog.dispose();
// }
//}
//});
return aDialog;
}
};
final JDialog aDialog = aPane.createDialog(WPApp.getWPAppInstance().getTopFrame().getDialogParent(), WPApp.resMsg.getString("Find_Title"));
//handle of FindNext Button.
//for enabling and disabling of find next button.
final JButton aFindButton = ((JButton)((JPanel)aPane.getComponent(1)).getComponent(0));
aFindButton.setEnabled(false);
itsTextField.addKeyListener(new KeyAdapter()
{
public void keyReleased(KeyEvent e)
{
if(itsTextField.getText().equals(""))
aFindButton.setEnabled(false);
else
aFindButton.setEnabled(true);
}
});
aFindButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
itsSequenceEditor.find(itsTextField.getText()); }
});
//handle of Cancel Button.
JButton aButton = ((JButton)((JPanel)aPane.getComponent(1)).getComponent(1));
aButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
aDialog.setVisible(false);
aDialog.dispose();
}
});
aDialog.show();
May be it would help.
Rachna