joptionpane

Clicking the cancel button showInputDialogue

拟墨画扇 提交于 2019-12-19 06:00:05
问题 I have a question in regards to pressing the cancel button of my inputDialoguebox. I have asked a similar question before so I apologize if I seem to repeat myself. The main problem I have is that my code executes regardless of me pressing cancel and a socket connection does get made even if I don't add any input. Why does this happen and how can I avoid this? String input = ""; try { InetAddress host = InetAddress.getLocalHost(); String hostAddress = host.getHostAddress(); //setting label to

How to change the button backgrounds inside JOptionPane

时光总嘲笑我的痴心妄想 提交于 2019-12-18 12:39:21
问题 I was wondering if anybody knew if it was possible to change the background color on the buttons inside a JOptionPane . I know how to change the entire JOptionPane background using a UIManager , but know what I want is to set the individual okButton, cancelButton, and so on within the JOptionPane to separate individual colors. If I can do this, how would I do this? Thanks for the help. 回答1: There is no direct way to do this. But if you really want to give it a try, then you will need to read

Display array in JOptionPane

只谈情不闲聊 提交于 2019-12-18 09:38:39
问题 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

Resize dialog message (JOptionPane) for long sentence with fixed width

喜欢而已 提交于 2019-12-18 03:43:54
问题 I'm trying to resize the height of the dialog box ( JOptionPane ) for long sentence with hyperlink. My code is .. public class DialogTest { public static void main(String[] args) throws Exception { JTextPane jtp = new JTextPane(); Document doc = jtp.getDocument(); for (int i = 0; i < 50; i++) { doc.insertString(doc.getLength(), " Hello Java World ", new SimpleAttributeSet()); if ((3 == i) || (7 == i) || (15 == i)) { doc.insertString(doc.getLength(), " Hello Java World ", new

JOptionPane without button

三世轮回 提交于 2019-12-18 02:46:07
问题 I need to present a information message that needs to be in the screen for 5 seconds, during this time, user can't close the dialog. The specification says clearly that the dialog shouldn't have any button. Is there a way I can use JoptionPane.showMessageDialog in a way that the dialog have no button? 回答1: How about this way using showOptionDialog , maybe not showMessageDialog , but the same thing when we have no buttons or place to enter text (downfall is it can be closed by user):

JOptionPane without button

蹲街弑〆低调 提交于 2019-12-18 02:46:05
问题 I need to present a information message that needs to be in the screen for 5 seconds, during this time, user can't close the dialog. The specification says clearly that the dialog shouldn't have any button. Is there a way I can use JoptionPane.showMessageDialog in a way that the dialog have no button? 回答1: How about this way using showOptionDialog , maybe not showMessageDialog , but the same thing when we have no buttons or place to enter text (downfall is it can be closed by user):

Java Swing — Key Input with JPanel added to JOptionpane

江枫思渺然 提交于 2019-12-17 21:22:21
问题 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

JOptionPane not displaying correctly?

亡梦爱人 提交于 2019-12-17 20:38:30
问题 Today I updated my jdk and docs from 7 to 8. I made a few changes to my program, and now when I try to have the program use JOptionPane, JLabel, ..., everything messes up. I made a separate tester class whose sole purpose is to run a single JOptionPane box and the error still occurred. Below is a picture of what the dialog box looks like. Is there something seriously wrong with Java 8? import javax.swing.JOptionPane; public class CirclePointTester { public static void main(String [] args) {

JOptionPane showInputDialog position

自古美人都是妖i 提交于 2019-12-17 20:36:27
问题 How can I specify the position of a JOptionPane. Can anyone make a class that extends JOptionPane.showInputDialog that also takes in an x,y position? 回答1: You can use JOptionPane's setLocation(...) method. OR Instead of using JOptionPane you can extends a JDialog, and then specify it's location on the screen. Here is one working code sample as adviced by @HovercraftFullOfEels , just this example will help you to get input from the user as you asked for : import javax.swing.*; public class

How to make JOptionPane.showConfirmDialog have No selected by default?

故事扮演 提交于 2019-12-17 19:57:03
问题 I implemented a Save As dialog in Java that prompts the user if the file already exists, and I want the No option to be selected by default. How do I do this? Here is my current code: JFileChooser chooser = new JFileChooser() { public void approveSelection() { File selectedFile = getSelectedFile(); if (selectedFile != null && selectedFile.exists( ) ) { int response = JOptionPane.showConfirmDialog( this, "The file " + selectedFile.getName() + " already exists." + " Do you want to replace the