> You may use a JFormattedTextField (using a MaskFormatter) and you may
> further use this text field as message parameter to call any of the
> JOptionPane.showXXXDialog methods.
>From what I understand about JOptionPane, the message parameter is only
for the labe text you want displayed to the operator, such as: "Please
enter the IP Address:".
I don't think the message parameter is for the data entry TextField.
The data entry text field is where I want the formatting to take place.
I tried a quick and dirty version from what I understood you were
suggesting. But the text that was affected by the message parameter was
the Label text for the Dialog box.
try
{
JFormattedTextField ft = new JFormattedTextField();
MaskFormatter formatter = new
MaskFormatter("###.###.###.###");
formatter.install(ft);
JOptionPane.showInputDialog(null ,formatter);
} catch (Exception e)
{
}
If I'm wrong in how you ment to use the message parameter could you
please clarify. Thanks
Michael Rauscher - 27 Sep 2006 23:02 GMT
dcMan schrieb:
>> You may use a JFormattedTextField (using a MaskFormatter) and you may
>> further use this text field as message parameter to call any of the
[quoted text clipped - 5 lines]
>
> I don't think the message parameter is for the data entry TextField.
Please read the API:
message
A descriptive message to be placed in the dialog box. In the most
common usage, message is just a String or String constant. However,
the type of this parameter is actually Object. Its interpretation
depends on its type:
...
Component
The Component is displayed in the dialog.
Here's a more "complicated" example where I use a panel as the message
instead of the textfield - this is because I want to show some label in
front of the input field.
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class Test {
public static final void main( String args[] ) throws Exception {
JPanel panel = new JPanel( new BorderLayout(5,0) );
panel.add( new JLabel("Input: "), BorderLayout.WEST );
MaskFormatter formatter = new MaskFormatter("###.###.###.###");
JFormattedTextField text = new JFormattedTextField(formatter);
panel.add( text );
JOptionPane.showMessageDialog( null, panel );
JOptionPane.showMessageDialog( null,
"You've entered \"" + text.getText() + "\"");
}
}
Again, instead of (ab)using JOptionPane you could create the same by
using a JDialog.
Bye
Michael
dcMan - 28 Sep 2006 14:25 GMT
Thanks Michael,
I did try to go through the API. But I guess just starting out in Java
and Swing, I didn't fully understand what the documentation was
informing me of what I could do.
Thanks for your example also.
Greg
Michael Rauscher - 28 Sep 2006 15:49 GMT
dcMan schrieb:
> Thanks Michael,
> I did try to go through the API. But I guess just starting out in Java
> and Swing, I didn't fully understand what the documentation was
> informing me of what I could do.
In fact, this part (message parameter) of the API is a bit confusing.
One could interprete "The Component is displayed in the dialog" so that
the Component is just rendered. In that case the example wouldn't work.
That's why I've written "(ab)using".
Luckily the component is not just rendered. It is added to the message
area of the dialog.
Bye
Michael