joptionpane

Display array in JOptionPane

家住魔仙堡 提交于 2019-11-29 17:59:42
I'm struggling to figure out how to show the contents of my array in a JOptionPane. The array includes an item, price, quantity and priority.For example I'd want it to look like this: "Apples 2.99 2 1" "Cereal 3.99 3 2" I currently have the array outputting to the console because I haven't been able to 'display' the array correctly. Here's what I have as of now: I appreciate all and any help! import java.text.NumberFormat; import javax.swing.JOptionPane; public class ShopList { public static void main(String[] args) { String enterName = JOptionPane.showInputDialog(null, "Username: "); for (int

GUI in java “go to previous/next” option?

只愿长相守 提交于 2019-11-29 16:48:17
Is there a way to have an option to go the a previous message dialog box or a next one? I have a program where after all the input and math calculations is done, a message dialog box appears with the information for "Person 1" then you press ok and the one for "Person 2" appears. It would be nice if there could be an option to be able to navigate between the different dialog boxes. Here is the part of the program that prints the messages. for (i = 0; i < NumEmployees; i++) { JOptionPane.showMessageDialog(null, "Employee: " + names[i] + "\n" + "ID: " + data[i][0] + "\n" + "Hours worked: " +

Add Image to JOptionPane

不羁岁月 提交于 2019-11-29 15:13:03
I'm wondering How To Add Image To MessageDialog Box. I tried the code below and the image was nowhere to be found else if(button == B){ String text = "blahblahblahblahblah"; JTextArea textArea = new JTextArea(text); textArea.setColumns(30); textArea.setLineWrap( true ); textArea.setWrapStyleWord( true ); textArea.setSize(textArea.getPreferredSize().width, 1); Font font = new Font("Verdana", Font.BOLD, 12); textArea.setFont(font); textArea.setForeground(Color.BLUE); JOptionPane.showMessageDialog( null, textArea, "Border States", JOptionPane.PLAIN_MESSAGE); image2 = new ImageIcon(getClass()

How do I Prompt the user to enter a password before entering the main program?

旧巷老猫 提交于 2019-11-29 14:44:44
What I need to do is to prompt the user with a username and password (authentication is done locally) and if it checks out, the user would then be able to access the main program body. public static void main(String[] args){ //String input = JOptionPane.showInputDialog("Enter password to continue: "); //input2 = Integer.parseInt(input); // followed by the creation of the main frame new Cashier3(); Cashier3 frame = new Cashier3(); frame.setTitle("CASHIER 2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); is there any quick way to go about doing this? You can

Making a JOptionPane with 4 options

本秂侑毒 提交于 2019-11-29 10:09:58
I need to make a custom dialog with 4 options but as far as I can tell you can only have one with three options. Here is how I would make an option pane with 3 options: Frame refFrame = DialogUtils.getReferenceFrame(); ///TODO: /// - Use DialogUtils int option = JOptionPane.showOptionDialog(refFrame, msg, rsc.str("918"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, DialogUtils.INFO_ICON, options, options[0]); But I could not find some sort of open ended substitution for YES_NO_CANCEL_OPTION. Is there a way to make the JOptionPane allow four choices? Peter You can use any

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

一笑奈何 提交于 2019-11-29 04:38:20
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. Eng.Fouad Just add a custom JPanel as a message to JOptionPane.showOptionDialog() : String[] options = {"OK"}; JPanel panel = new JPanel(); JLabel lbl = new JLabel("Enter Your name: "); JTextField txt = new JTextField(10); panel.add(lbl); panel.add(txt); int

How can I make JOptionPane dialogs show up as a task on the taskbar?

。_饼干妹妹 提交于 2019-11-29 02:20:06
问题 Edit: The question follows the horizontal rule; my own answer precedes it. Based on help from Oscar Reyes, I crafted this solution: import javax.swing.JOptionPane; import javax.swing.JFrame; public class MyApp extends JFrame { public static void main(String [] args) { new MyApp(); } public MyApp() { super("MyApp"); setUndecorated(true); setVisible(true); setLocationRelativeTo(null); String i = JOptionPane.showInputDialog(this, "Enter your name:", getTitle(), JOptionPane.QUESTION_MESSAGE); if

JOptionPane Yes or No window

笑着哭i 提交于 2019-11-28 18:27:10
I am trying to create a message with a Yes or No button. Then a window will appear with a certain message that depends on if the user clicked Yes or No. Here is my code: public class test{ public static void main(String[] args){ //default icon, custom title int n = JOptionPane.showConfirmDialog( null, "Would you like green eggs and ham?", "An Inane Question", JOptionPane.YES_NO_OPTION); if(true){ JOptionPane.showMessageDialog(null, "HELLO"); } else { JOptionPane.showMessageDialog(null, "GOODBYE"); } System.exit(0); } } Right now it prints HELLO whether or not you press Yes or No. How do I get

Java Swing — Key Input with JPanel added to JOptionpane

廉价感情. 提交于 2019-11-28 14:43:31
When I run the code, the added Example1 class to the JOptionPane (in Frame) should get keyInput and then change the y value of the player instance (in example1), but it doesn't work. Also, how would I be able to rotate the ship on its axis and then move in the direction its facing? Currently it moves in the direction its rotated towards, but it rotates on what seems the coordinates 0,0. Frame import javax.swing.*; import java.awt.*; /** * Created by griffin on 12/7/2015. */ public class Frame extends JFrame { public Frame() { initUI(); } private void initUI() { JTabbedPane jtp = new

ImageIcon Help + Close a JOptionPane

筅森魡賤 提交于 2019-11-28 14:42:42
I'm trying to get the PayPal logo come up when you click the 'rightbutton' is clicked. Unfortunately, all that shows is the default Java logo with the cup of coffee and a pen. Also, how can I make it so once you click "OK" or "Cancel" it closes the JOptionPane, currently, when you click "OK" nothing happens, it keeps giving you the "OK" / "Cancel" option. rightbutton = new JButton("Right."); add(rightbutton); rightbutton.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent event){ //what do we want to happen when we //click the button final ImageIcon icon = new