joptionpane

JOptionPane output text copy

别等时光非礼了梦想. 提交于 2019-11-30 20:28:53
问题 I have no experience with JOptionpane but I need a simple program to simplify my life. The code I need help with is below: public static void main (String[] args) { String input = ""; input = JOptionPane.showInputDialog("Enter code"); JOptionPane.showMessageDialog(null, toStringU(toArray(input)), "RESULT", JOptionPane.INFORMATION_MESSAGE); } toStringU method gives me a long long text I want to run it without any compiler (a standalone application, double click, put info and take results). And

JOptionPane Input to int

泄露秘密 提交于 2019-11-30 13:28:30
I am trying to make a JOptionPane get an input and assign it to an int but I am getting some problems with the variable types. I am trying something like this: Int ans = (Integer) JOptionPane.showInputDialog(frame, "Text", JOptionPane.INFORMATION_MESSAGE, null, null, "[sample text to help input]"); But I am getting: Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer Which sounds logical yet, I cannot think of another way to make this happen. Thanks in advance Simply use: int ans = Integer.parseInt( JOptionPane.showInputDialog(frame,

How to change the button backgrounds inside JOptionPane

落爺英雄遲暮 提交于 2019-11-30 07:41:39
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. There is no direct way to do this. But if you really want to give it a try, then you will need to read the JOptionPane API which gives code that shows you how to manually create and display a JOptionPane without

ImageIcon Help + Close a JOptionPane

烈酒焚心 提交于 2019-11-30 06:07:24
问题 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

Java - How to add a JOptionPane for Yes and No options

那年仲夏 提交于 2019-11-30 06:01:29
问题 So, I've read the Java API, but still can't seem to make heads or tails about how to do this. And believe me I have tried. I want an ActionListener to cause a message box with the text 'Do you really want to exit?', with options yes and no which exits the program or not depending on the selected button. Here's what I have for the ActionListener before I started to break it with the message box: exitItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) {

ActionListener on JOptionPane

ε祈祈猫儿з 提交于 2019-11-30 06:01:23
问题 I am following the Oracle tutorial on how to create a custom dialog box: http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html I have two buttons: Save Object and Delete Object which when clicked should execute a certain piece of code. Unfortunately I can't seem to add any ActionListener to the JOptionPane buttons so when they're clicked nothing happens. Can anyone help tell me how I can go about doing this? Here is the class I have for the dialog box so far: class

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

蹲街弑〆低调 提交于 2019-11-30 04:53:02
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(null != i) { JOptionPane.showInputDialog(this, "Your name is:", getTitle(), JOptionPane.INFORMATION

How do you change the size and font of a joptionpane?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 19:03:56
问题 Can you change the font and size of the text of a JOptionPane? I tried it and it works only if I "run file" on that specific java class. If you start the whole project it does not change the font. I only want to change only a specific JOptionPane not all of them. Here is the code: UIManager.put("OptionPane.messageFont", new FontUIResource(new Font( "Arial", Font.BOLD, 18))); JOptionPane.showMessageDialog(null,"MESSAGE","ERROR",JOptionPane.WARNING_MESSAGE); 回答1: It's really easy. JOption pane

To break a message in two or more lines in JOptionPane

∥☆過路亽.° 提交于 2019-11-29 18:56:46
问题 try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String connectionUrl = "jdbc:sqlserver://"+hostName.getText()+";" + "databaseName="+dbName.getText()+";user="+userName.getText()+";password="+password.getText()+";"; Connection con = DriverManager.getConnection(connectionUrl); if(con!=null){JOptionPane.showMessageDialog(this, "Connection Established");} } catch (SQLException e) { JOptionPane.showMessageDialog(this, e); //System.out.println("SQL Exception: "+ e.toString()); }

How to close JOptionPane automatically?

微笑、不失礼 提交于 2019-11-29 18:04:18
I have a Thread running and in the time while the thread working i want to display a JOptionPane.showMessageDialog saying that the application is working and after thread is stopped, JOptionPane will close automatically and OK button will be deactivated the whole time. My Main code : class Index { public static void main(String args[]) { NewThread ob1 = new NewThread("One"); NewThread ob2 = new NewThread("Two"); NewThread ob3 = new NewThread("Three"); System.out.println("Thread One is alive: "+ ob1.t.isAlive()); System.out.println("Thread Two is alive: "+ ob2.t.isAlive()); System.out.println(