Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Message Box without OK button

Posted on 2003-11-19
8
Medium Priority
?
1,402 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.

604 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