?
Solved

Message Box without OK button

Posted on 2003-11-19
8
Medium Priority
?
1,366 Views
Last Modified: 2012-06-21
Hi,

I need a message box similar to JOptionPane.showMessageDialog() but without the OK button (I want the program to close it.) Is there anyway to do this without coding a custom dialog?

Thanks,

Wall
0
Comment
Question by:wallway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 9783519
Use a JDailog :

JDaiolg g = new JDialog();
0
 
LVL 15

Accepted Solution

by:
jimmack earned 150 total points
ID: 9783552
What is wrong with creating your own dialog?

                JDialog myDialog = new JDialog((JFrame)null, "Title");
                myDialog.getContentPane().add(new JLabel("My message", SwingConstants.CENTER));
                myDialog.pack();
                myDialog.show();
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9783558
Hi Javatm.  Perhaps I shouldn't have taken the time to test my layout ;-)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:Javatm
ID: 9783604
jimmack, thats okey friend :) we are professionals.
0
 
LVL 3

Expert Comment

by:monkesdb
ID: 9784394
if you just want there to be no cancel button then you should be able to do it in one line.


JDialog dialog = new JOptionPanel("Message Goes Here", JOptionPanel.PLAIN_MESSAGE, CANCEL_OPTION).createDialog(null, "Title");


i've not tried it so you might have to "dialog.show()" or something to see it but that should do the trick.

if this doesn't work please let me know.
0
 

Author Comment

by:wallway
ID: 9788539
Thanks for the replies.


JDialog myDialog = new JDialog((JFrame)null, "Title");
myDialog.getContentPane().add(new JLabel("My message", SwingConstants.CENTER));
myDialog.pack();
myDialog.show();

This kindof works, except it shows in the top left hand corner, is too small, and doesn't show the message. I will have to do more configuration to get it to look like a normal information box.

JDialog dialog = new JOptionPanel("Message Goes Here", JOptionPanel.PLAIN_MESSAGE, CANCEL_OPTION).createDialog(null, "Title");

This one kinda works as well, however the buttons are still showing. But it is the right size and displays in the center as I need it to.

Wall


0
 
LVL 15

Expert Comment

by:jimmack
ID: 9788574
To get the dialog to show in the centre of your frame, you need to supply the parent as the first parameter in the constructor, eg:

JFrame myFrame = new JFrame("Frame title");

JDialog myDialog = new JDialog(myFrame, "Title");

To resize it, just use:

myDialog.setSize(new Dimension(200, 100));  //  or whatever size you need.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9788581
The setSize() should replace the pack() method ;-)
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question