Java Multiple Input Dialog
I have a Java application and I want to open a new dialog from the main interface where the user can enter his name, surname and country and then click ok. How can I open a dialog which has a number of different input fields a开发者_如何转开发nd then save that information in a variable?
Extend JDialog and add some JTextFields and maybe some JComboBoxes. then finish it off with some JButtons.
You could also look into JGoodies Forms framework; it's nice and free.
EDIT: Composition example
Based on Pete's comment I dug up this example using composition rather than overriding JDialog.
You would want to add getter like
public String getFirstName() {
return field.getTest();
}
To gain access to relevant input.
This forum post could be helpful.
One possibility to make a custom JDialog is to create a custom JPanel with all the bells and whistles that you need and use that as the Component in one of the static JOptionPane functions.
With java and swing you have to write some code. I build a library which creates a dialog with different inputs in a few lines. It's called UiBooster.
FilledForm form = new UiBooster()
.createForm("Personal informations")
.addText("Whats your first name?")
.addTextArea("Tell me something about you")
.addSelection(
"Whats your favorite movie?",
Arrays.asList("Pulp Fiction", "Bambi", "The Godfather", "Hangover"))
.show();
精彩评论