joptionpane

Add actionlistener to a button in joptionPane (java)

情到浓时终转凉″ 提交于 2020-01-07 03:04:10
问题 How can I add ActionListener to a JButton in JOptionPane . So that when I press on the button, it excutes a certain code. I tried to use this code, but it is not working: JButton button1= new JButton("Button 1"); int value = JOptionPane.showOptionDialog(null, "Here's a test message", "Test", JOptionPane.YES_OPTION , JOptionPane.QUESTION_MESSAGE, null,new Object[]{button1}, button1); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //code to excute

Creating a Simple Bar Chart in Java - Reads Data and Outputs Bar Graph

℡╲_俬逩灬. 提交于 2020-01-06 15:08:58
问题 Im required to create a simple bar chart for one of my projects. This program requires an input of 1 to 9 integers that are greater than zero. The program is then required to display a very simple bar graph with the integers displayed above the bars. My professor did not explain this program very well to me and this is the first time working with graphics. The program requires: A class "SimpleBarChart" (which will extend Frame) with private variables Bar[] bars and int [] inputData among

I want to display a message showing what I selected (Java)

只谈情不闲聊 提交于 2020-01-06 03:08:04
问题 I'm doing a project (something like a restaurant) for collage, and I'm not very good in Java (they didn't really try to teach us). The principle of the project is to show a message saying what radio buttons and check boxes I've selected. I have 5 radio buttons, they are for selecting a meal, and 5 check boxes for selecting a side dish. I've managed to have the radio buttons work but I don't know how to make the check boxes work... This is the code for the radio buttons (this goes for all 5):

JOptionPane issue using internal dialog

孤街浪徒 提交于 2020-01-05 02:30:33
问题 String result = JOptionPane.showInputDialog(this, temp); result value will be the inputted value. String result = JOptionPane.showInternalInputDialog(this, temp); result value will be null even you inputted a string. temp is a panel that will contain in the JOptionPane. This JOptionPane will show on top of another customized JOptioPane. 回答1: JOptionPane.showInternalInputDialog is to be used with JDesktopPane / JInternalFrame s only, where this is the JDesktopPane / JInternalFrame s instance.

JOptionPane issue using internal dialog

假如想象 提交于 2020-01-05 02:30:19
问题 String result = JOptionPane.showInputDialog(this, temp); result value will be the inputted value. String result = JOptionPane.showInternalInputDialog(this, temp); result value will be null even you inputted a string. temp is a panel that will contain in the JOptionPane. This JOptionPane will show on top of another customized JOptioPane. 回答1: JOptionPane.showInternalInputDialog is to be used with JDesktopPane / JInternalFrame s only, where this is the JDesktopPane / JInternalFrame s instance.

Java setLocation() mishap

大城市里の小女人 提交于 2020-01-03 17:09:58
问题 I'm in the beginning stages of creating a program to operate an Employee/Customer system, right now I have just created the Login GUI, but I am having a little bit of a problem with the setLocation(); method. I set it to 250, 250, but it makes the height of my GUI go absolutely nuts. My code is below if anyone would be able to fix this. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Main extends JFrame { private static final int HEIGHT = 1003; private static

Put a doClick inside a JOptionPane

家住魔仙堡 提交于 2020-01-03 05:58:07
问题 I am a beginner to java and I have some trouble on making the doClick buttons. I don't understand how it works and I need it in my code. JButton easyb = new JButton("Easy"); JButton mediumb = new JButton("Medium"); JButton hardb = new JButton("Hard"); String fn = JOptionPane.showInputDialog("Choose your level \n", easyb.doClick() ,mediumb.doClick(), hardb.doClick() , "\n \n Easy are words you know everyday \n Medium are words that you have seen before \n Hard are words that you have rarely

JOptionPane displays behind the parent JFrame

时光怂恿深爱的人放手 提交于 2020-01-02 17:55:23
问题 I created a swing application on Windows OS. One of my JDialog (whose window is parentJFrame) shows a JOptionPane. JOptionPane.showMessageDialog(parentJFrame, "I am a JOption"); . At the run time, the parentJFrame setAlwaysOnTop(true) . Even though it has set alwaysOnTop-TRUE, the JOptionPane appeares on the parentJFrame on Windows OS. but When I ran it on Linux OS,JOptionPane displays behind the parentJFrame.(May be the reason is that parentJFrame alwyasOnTop is true , but how JRE runs the

How do I create a JOptionPane.showOptionDialog box in Java (Swing) with custom JButtons?

守給你的承諾、 提交于 2020-01-02 11:03:10
问题 After reading through all the Dialog tutorials for a while, there seems to be no apparent way to do this. The closest thing seems to be JOptionPane.showOptionDialog , but I am limited by the optionType parameter here. EDIT: I figured out the problem, but have a new one. It seems that the options parameter being specified in showOptionDialog needs to be fairly simple objects (strings or just 'objects', not JButton or the like). I was trying to put an array of custom-factory-created JButtons

How can I dismiss one JOptionPane upon emergence of another JOptionPane in the GUI

穿精又带淫゛_ 提交于 2020-01-01 10:42:46
问题 As you have seen from my subject above, I would like to know how can I dismiss a JOptionPane which became irrelevant because of another JOptionPane and because the user ,for some reason, didn't dismiss the first one by himself clicking ok button (for example). I've seen some ware in other site similar question, and people suggested to do simply: JOptionPane.getRootFrame().dispose(); But how can I store a reference for each JOptionPane I have and to be able to dismiss only that wanted one.