joptionpane

JOptionPane won't show its dialog on top of other windows

痞子三分冷 提交于 2019-12-17 19:38:49
问题 I have problem currently for my swing reminder application, which able to minimize to tray on close. My problem here is, I need JOptionPane dialog to pop up on time according to what I set, but problem here is, when I minimize it, the dialog will pop up, but not in the top of windows when other application like explorer, firefox is running, anyone know how to pop up the dialog box on top of windows no matter what application is running? 回答1: Create an empty respectively dummy JFrame, set it

How to close message dialog programmatically?

孤街醉人 提交于 2019-12-17 16:37:13
问题 I have a question about joptionpane. Using JOptionPane.showMessageDialog(...), we can create a message dialog. But how to close it programmatically? 回答1: You could always get a reference to the JOptionPane by getting the WindowAncestor of any component it's holding, and then call dispose() or setVisible(false) on the Window returned. The Window can be obtained by using SwingUtilities.getWindowAncestor(component) For example: import java.awt.Window; import java.awt.event.ActionEvent; import

JOptionPane Passing Custom Buttons

巧了我就是萌 提交于 2019-12-17 09:59:09
问题 I'm trying to get the value returned by custom buttons passed to JOptionPane. However the buttons I pass don't return a value at all. Only when the exit button is pressed is a value of -1 returned. I need this because I am changing the properties of the buttons enabled or disabled. I assume I need the buttons to return some information to the JOptionPane in some way. Any idea? JButton button1= new JButton("Button 1"); JButton button2= new JButton("Button 2"); button1.setEnabled(false); int

JOptionPane - check user input and prevent from closing until conditions are met

六眼飞鱼酱① 提交于 2019-12-17 06:14:14
问题 Please can someone tell me if there is a convenient way of prevent JOptionPane from closing upon clicking OK unless the conditions for user input fields are met? Or do I have no choice but to use JFrame ? My validation logic so far. Doesn't seem to work because the buttons are one-time clickable to some reason... final JDialog dialog3 = new JDialog(OmniGUI.getFrame(), "Create new Node - id:" + newNodeID); dialog3.setContentPane(theOPane); dialog3.setDefaultCloseOperation(JDialog.DO_NOTHING_ON

Closing A JOptionPane Programmatically

笑着哭i 提交于 2019-12-17 05:12:41
问题 I am working on a project in which I would like to close a generic JOptionPane programmatically (by not physically clicking on any buttons). When a timer expires, I would like to close any possible JOptionPane that may be open and kick the user back to the login screen of my program. I can kick the user back just fine, but the JOptionPane remains unless I physically click a button on it. I have looked on many sites with no such luck. A doClick() method call on the "Red X" of the JOptionPane

Multiple input in JOptionPane.showInputDialog

血红的双手。 提交于 2019-12-17 03:01:36
问题 Is there a way to create multiple input in JOptionPane.showInputDialog instead of just one input? 回答1: 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

How to align multiple textfields on a background image within a JOptionPane?

旧街凉风 提交于 2019-12-13 18:31:55
问题 I want to have multiple textfiled to be aligned in a customized order, so that they are on the top of the background image. I tried to use setBounds but it did not work: import javax.swing.*; public class TestJP { public static void main(String[] args) { JLabel myLabel = new JLabel(); myLabel.setIcon ( new ImageIcon("system\\myBackground.jpg")); myLabel.setBounds(0,0,750,500); JTextField login = new JTextField(5); login.setBounds(50,50,20,100); // This does not work JPasswordField password =

How to open this program on a window?

余生颓废 提交于 2019-12-13 10:26:59
问题 Can anyone help me with my if and else statements? It's only saying "Exit Goodbye" whenever I input something, which should only happen when I enter -0. My teacher is gone for the week, so I don't have anyone to ask for help. package game; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Random; import javax.swing.JOptionPane; public class GameFrame { /** * @param args */ public static void main(String[] args) { // num1 - Variable to store the first value //

Check if input is an integer in JOptionPane

让人想犯罪 __ 提交于 2019-12-13 08:19:26
问题 JFrame frame2 = new JFrame("Boxes"); String askBoxes= JOptionPane.showInputDialog(frame2, "How many boxes?", "# of boxes", JOptionPane.QUESTION_MESSAGE); if(askBoxes == null) { JOptionPane.showMessageDialog(null, "User pressed cancel, exiting program now!"); System.exit(0); } else { numBoxes= Integer.parseInt(askBoxes); } I am supposed to create a program that asks for inputs as integers but is also able to return an error message if the user inputs something other than an integer. I've

Make a simple Java OptionPane Counter

假装没事ソ 提交于 2019-12-13 07:23:43
问题 Hi I basically just want to make a JOptionPane window which has a number on top and 2 Buttons "+1" and "-1" if i press one of these Buttons the Number above should Decrease or Increase by 1. It would be very nice if someone could help me with posting a code or explaining how to make it to me. Thanks 回答1: I would just create a simple JDialog with 3 components, a JLabel and two JButtons. Add ActionListeners to each of the buttons to either add 1 or subtract one. Start by reading the Swing