Re: Can JOptionPane use a MaskFormatter for data input
- From: Michael Rauscher <michlmann@xxxxxx>
- Date: Thu, 28 Sep 2006 00:03:01 +0200
dcMan schrieb:
Michael Rauscher wrote: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.
for the labe text you want displayed to the operator, such as: "PleaseFrom what I understand about JOptionPane, the message parameter is only
enter the IP Address:".
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
.
- Follow-Ups:
- References:
- Can JOptionPane use a MaskFormatter for data input
- From: dcMan
- Re: Can JOptionPane use a MaskFormatter for data input
- From: Deniz Dogan
- Re: Can JOptionPane use a MaskFormatter for data input
- From: Michael Rauscher
- Re: Can JOptionPane use a MaskFormatter for data input
- From: dcMan
- Can JOptionPane use a MaskFormatter for data input
- Prev by Date: Re: Java to UML
- Next by Date: Re: Java to UML
- Previous by thread: Re: Can JOptionPane use a MaskFormatter for data input
- Next by thread: Re: Can JOptionPane use a MaskFormatter for data input
- Index(es):