The Artima Developer Community
Sponsored Link

Java Answers Forum
JOptionPane Problem

4 replies on 1 page. Most recent reply: Sep 19, 2002 1:33 AM by Lucio

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Lucio

Posts: 14
Nickname: luzzy00
Registered: Jul, 2002

JOptionPane Problem Posted: Sep 5, 2002 4:18 AM
Reply to this message Reply
Advertisement
int result=JOptionPane.showConfirmDialog(this,
"messagge",
"title",
JOptionPane.YES_NO_OPTION);
How can I say what button must be selected when show the optionPane?
I'd like select the button "No"


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: JOptionPane Problem Posted: Sep 5, 2002 6:26 PM
Reply to this message Reply

import javax.swing.*;
class JOptionTest extends JFrame{

public static void main(String[] args){
JOptionTest tester = new JOptionTest();
tester.test();
System.exit(0);
}

public void test(){
String message = "Are you sure?";
int result=JOptionPane.showConfirmDialog(this, message, message, JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.NO_OPTION){
JOptionPane.showMessageDialog(this,"You picked No.");
}else{
JOptionPane.showMessageDialog(this,"You picked Yes.");
}
}
}

Lucio

Posts: 14
Nickname: luzzy00
Registered: Jul, 2002

Re: JOptionPane Problem Posted: Sep 13, 2002 3:15 AM
Reply to this message Reply
thank you to have replyed.
I don't speak a good English,and so you don't have understand my problem.
I'd like that the button "No" is selected when I show the OptionPane.

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: JOptionPane Problem Posted: Sep 17, 2002 2:29 PM
Reply to this message Reply
In the test2 method I used the method:
public static int showOptionDialog(
Component parentComponent,
Object message,
String title,
int optionType,
int messageType,
Icon icon,
Object[] Object initialValue)

if you look carefully at the dialog that comes up the yes button is default selected in the test1()
and the no button is selected in test2().


import javax.swing.*;
class JOptionTest extends JFrame{
public static void main(String[] args){
JOptionTest tester = new JOptionTest();
tester.test1();
tester.test2();
System.exit(0);
}

public void test1(){
String message = "Are you sure?";
int result=JOptionPane.showConfirmDialog(this, message, message, JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.NO_OPTION){
JOptionPane.showMessageDialog(this,"You picked No.");
}else{
JOptionPane.showMessageDialog(this,"You picked Yes.");
}
}

public void test2(){
String message = "Are you sure?";
Object[] options = {"Yes", "No"};
int result = JOptionPane.showOptionDialog(this,
message,
message,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[1]);
if (result == JOptionPane.NO_OPTION){
JOptionPane.showMessageDialog(this,"You picked No.");
}else{
JOptionPane.showMessageDialog(this,"You picked Yes.");
}

}
}

Lucio

Posts: 14
Nickname: luzzy00
Registered: Jul, 2002

Re: JOptionPane Problem Posted: Sep 19, 2002 1:33 AM
Reply to this message Reply
thank you very very much

Flat View: This topic has 4 replies on 1 page
Topic: Int Random Numbers. HELP! Previous Topic   Next Topic Topic: Open a file with an external program

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use