I am currently developing a java application.
I want to show a new Window which contains a text area and a button.
Do you have any ideas?
A class that implements a menu which can be dynamically popped up at a specified position within a component. As the inheritance hierarchy implies, a PopupMenu can be used anywhere a Menu can be used.
The showMessageDialog method creates a basic one-button dialog box. The showOptionDialog method, however, enables you to customize features like the number of buttons, the words on the buttons, and even allows you to ask for input in your dialog box. Notice that line 1 in the code above imports the Swing package.
JOptionPane; then you can call it using this: JOptionPane. showMessageDialog(null, "ALERT MESSAGE", "TITLE", JOptionPane. WARNING_MESSAGE);
The same answer : JOptionpane with an example :)
package experiments; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; public class CreateDialogFromOptionPane { public static void main(final String[] args) { final JFrame parent = new JFrame(); JButton button = new JButton(); button.setText("Click me to show dialog!"); parent.add(button); parent.pack(); parent.setVisible(true); button.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { String name = JOptionPane.showInputDialog(parent, "What is your name?", null); } }); } }
Hmm it has been a little while but from what I remember...
If you want a custom window you can just make a new frame and make it show up just like you would with the main window. Java also has a great dialog library that you can check out here:
How to Make Dialogs
That may be able to give you the functionality you are looking for with a whole lot less effort.
Object[] possibilities = {"ham", "spam", "yam"}; String s = (String)JOptionPane.showInputDialog( frame, "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog", JOptionPane.PLAIN_MESSAGE, icon, possibilities, "ham"); //If a string was returned, say so. if ((s != null) && (s.length() > 0)) { setLabel("Green eggs and... " + s + "!"); return; } //If you're here, the return value was null/empty. setLabel("Come on, finish the sentence!");
If you do not care to limit the user's choices, you can either use a form of the showInputDialog method that takes fewer arguments or specify null for the array of objects. In the Java look and feel, substituting null for possibilities results in a dialog that has a text field and looks like this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With