Reputation: 5046
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 and then save that information in a variable?
Upvotes: 0
Views: 6137
Reputation: 91
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();
Upvotes: 0
Reputation: 7358
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.
Upvotes: 1
Reputation: 104178
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.
Upvotes: 0