joptionpane

How to present a simple alert message in java?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 03:07:24
Coming from .NET i am so used calling Alert() in desktop apps. However in this java desktop app, I just want to alert a message saying "thank you for using java" I have to go through this much suffering: (using a JOptionPane) Is there an easier way? I'll be the first to admit Java can be very verbose, but I don't think this is unreasonable: JOptionPane.showMessageDialog(null, "My Goodness, this is so concise"); If you statically import JOptionPane.showMessageDialog this further reduces to showMessageDialog(null, "This is even shorter"); Bill the Lizard Assuming you already have a JFrame to

JOptionPane and reading integers - Beginner Java

夙愿已清 提交于 2019-11-28 02:20:06
I currently have code that reads the month, date, and year a user enters in one line (separated by spaces). Here is the code. Scanner input = new Scanner(System.in); int day = 0; int month = 0; int year = 0; System.out.printf("enter the month, date, and year(a 2 numbered year). Put a space between the month, day, and year"); month = input.nextInt(); day = input.nextInt(); year = input.nextInt(); This works fine, the second part is to display a message, if month * day == year, then it is a magical number, if not, then it is not a magical number. It has to be displayed in a dialog box. here is

JOptionPane displaying HTML problems in Java

你。 提交于 2019-11-28 01:42:50
Okay, so I have this code, it prompts a month and a year from the user and prints the calendar for that month. I'm having some problems though. the HTML font editing only affects the month. the days of the week are not aligned in columns correctly. Thanks! package calendar_program; import javax.swing.JOptionPane; public class Calendar { public static void main(String[] args) { StringBuilder result=new StringBuilder(); // read input from user int year=getYear(); int month=getMonth(); String[] allMonths={ "", "January", "February", "March", "April", "May", "June", "July", "August", "September",

Is there a way to only have the OK button in a JOptionPane showInputDialog (and no CANCEL button)?

大城市里の小女人 提交于 2019-11-27 18:33:00
问题 I've seen that this is possible in other types of dialog windows such as "showConfirmDialog", where one can specify the amount of buttons and their names; but is this same functionality achievable when using "showInputDialog"? I couldn't seem to find this type of thing in the API. Perhaps I just missed it, but any help is appreciated. 回答1: Just add a custom JPanel as a message to JOptionPane.showOptionDialog() : String[] options = {"OK"}; JPanel panel = new JPanel(); JLabel lbl = new JLabel(

Timer or other idea required to allow code to continue execution after calling method and JOptionPane

别等时光非礼了梦想. 提交于 2019-11-27 16:20:16
I need a way to allow my program to keep running code after this method is called. Currently, it waits for half an hour, gets the info, stores it to the object WeatherCard, and displays it, and repeats. But it hangs on the JOptionPane. I need a way to make it so that the program either keeps going underneath the JOptionPane or to close the pane after about 10 seconds. I am not sure how to work either into my code, currently public void printWeatherCard(WeatherCard w, JFrame controlFrame) throws MalformedURLException, IOException{ /* Displays a dialog box containing the temperature and location

Customize JOptionPane Dialog

◇◆丶佛笑我妖孽 提交于 2019-11-27 15:15: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 ImageIcon("images/gwhite.gif"),JLabel.CENTER); jop.add(im,BorderLayout.NORTH); jop.setVisible(true); But

JOptionPane Passing Custom Buttons

喜欢而已 提交于 2019-11-27 09:33:47
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 value = JOptionPane.showOptionDialog(null, "Heres a test message", "Test", JOptionPane.YES_NO_OPTION,

Java Dialog - Find out if OK is clicked?

↘锁芯ラ 提交于 2019-11-27 09:19:53
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 = new JTextField(20); GUI gui = new GUI(); Client client = new Client(); JOptionPane optionPane; public

JOptionPane to get password

此生再无相见时 提交于 2019-11-27 08:33:05
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. Yes, it is possible using JOptionPane.showOptionDialog() . Something like this: JPanel panel = new JPanel(); JLabel label = new JLabel("Enter a password:"); JPasswordField pass = new JPasswordField(10); panel.add(label); panel.add(pass); String[] options = new String[]{"OK

JOptionPane and reading integers - Beginner Java

﹥>﹥吖頭↗ 提交于 2019-11-27 04:52:54
问题 I currently have code that reads the month, date, and year a user enters in one line (separated by spaces). Here is the code. Scanner input = new Scanner(System.in); int day = 0; int month = 0; int year = 0; System.out.printf("enter the month, date, and year(a 2 numbered year). Put a space between the month, day, and year"); month = input.nextInt(); day = input.nextInt(); year = input.nextInt(); This works fine, the second part is to display a message, if month * day == year, then it is a