joptionpane

Customize JOptionPane Dialog

非 Y 不嫁゛ 提交于 2019-11-26 17:06:01
问题 I am learning java swing. The code below is a catch block which handles an IOException and shows a error message. catch(IOException e) { System.out.println("IOException"); JOptionPane.showMessageDialog(null,"File not found",null, JOptionPane.ERROR_MESSAGE); } I was thinking of declaring and customizing a JOptionPane of my own inside the catch block like the code below: JOptionPane jop=new JOptionPane(); jop.setLayout(new BorderLayout()); JLabel im=new JLabel("Java Technology Dive Log", new

Multiple input in JOptionPane.showInputDialog

左心房为你撑大大i 提交于 2019-11-26 15:12:50
Is there a way to create multiple input in JOptionPane.showInputDialog instead of just one input? Hovercraft Full Of Eels Yes. You know that you can put any Object into the Object parameter of most JOptionPane.showXXX methods , and often that Object happens to be a JPanel . In your situation, perhaps you could use a JPanel that has several JTextFields in it: import javax.swing.*; public class JOptionPaneMultiInput { public static void main(String[] args) { JTextField xField = new JTextField(5); JTextField yField = new JTextField(5); JPanel myPanel = new JPanel(); myPanel.add(new JLabel("x:"));

Java Dialog - Find out if OK is clicked?

笑着哭i 提交于 2019-11-26 14:39:08
问题 I have a dialog for a client-GUI that asks for the IP and Port of the server one wants to connect to. I have everything else, but how would I make it so that when the user clicks "OK" on my dialog box, that it runs something? Here's what I have so far: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JTextField; public class ClientDialog { JTextField ip = new JTextField(20); JTextField port

JOptionPane to get password

☆樱花仙子☆ 提交于 2019-11-26 14:10:59
问题 JOptionPane can be used to get string inputs from user, but in my case, I want to display a password field in showInputDialog . The way I need is the input given by the user should be masked and the return value must be in char[] . I need a dialog box with a message, password field, and two buttons. Can that be done? Thanks. 回答1: Yes, it is possible using JOptionPane.showOptionDialog(). Something like this: JPanel panel = new JPanel(); JLabel label = new JLabel("Enter a password:");

Can I use a Java JOptionPane in a non-modal way?

三世轮回 提交于 2019-11-26 11:27:17
问题 I am working on an application which pops up a JOptionPane when a certain action happens. I was just wondering if it was possible that when the JOptionPane does pop up how can you still use the background applications. Currently when the JOptionPane pops up I can\'t do anything else until I close the JOptionPane. EDIT Thanks for the reply guys and the information. Think ill leave this function out of the application cause it looks like it could be more hassle than necessary. 回答1: The

Java - How to create a custom dialog box?

别等时光非礼了梦想. 提交于 2019-11-26 09:36:10
问题 I have a button on a JFrame that when clicked I want a dialog box to popup with multiple text areas for user input. I have been looking all around to try to figure out how to do this but I keep on getting more confused. Can anyone help? 回答1: If you don't need much in the way of custom behavior, JOptionPane is a good time saver. It takes care of the placement and localization of OK / Cancel options, and is a quick-and-dirty way to show a custom dialog without needing to define your own classes

Closing a runnable JOptionPane

梦想与她 提交于 2019-11-26 09:14:09
问题 I have this Runnable window: EventQueue.invokeLater(new Runnable(){ @Override public void run() { op = new JOptionPane(\"Breaktime\",JOptionPane.WARNING_MESSAGE); dialog = op.createDialog(\"Break\"); dialog.setAlwaysOnTop(true); dialog.setModal(true); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); } }); Is it possible that I can have a timer here to close this within 1 or 2 minutes instead of clicking the OK button? 回答1: Yes, the trick would be to get the

Why does setSelected on JCheckBox lose effect?

我的未来我决定 提交于 2019-11-26 07:49:42
问题 Can someone explain to me why I lost the selection (set by setSelected() ) for JCheckBox when I put the JOptionPane into the ItemListener ? Is this a bug ? It is curious, that if this process is delayed with invokeLater() , setSelected() works correctly as I expected. from SSCCE import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ComponentEventDemo extends JPanel implements ComponentListener, ItemListener { private static final long serialVersionUID = 1L; private

Why JScrollPane in JOptionPane not showing all its content?

自古美人都是妖i 提交于 2019-11-26 05:54:37
问题 I am trying to add components to a JPanel, then put this panel into a JScrollPane, then put the JScrollPane in JOptionPane. The problem: only 19 line of components added. There is a for-loop that determine the number of lines of components, if you change the condition counter to 19 or less then all of them will be displayed. This is an SSCCE of the problem import java.awt.Dimension; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing

Text wrap in JOptionPane?

时光毁灭记忆、已成空白 提交于 2019-11-26 00:29:15
问题 I\'m using following code to display error message in my swing application try { ... } catch (Exception exp) { JOptionPane.showMessageDialog(this, exp.getMessage(), \"Error\", JOptionPane.ERROR_MESSAGE); } The width of the error dialog goes lengthy depending on the message. Is there any way to wrap the error message? 回答1: A JOptionPane will use a JLabel to display text by default. A label will format HTML. Set the maximum width in CSS. JOptionPane.showMessageDialog( this, "<html><body><p