File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JOptionPane. showMessageDialog() problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JOptionPane. showMessageDialog() problem" Watch "JOptionPane. showMessageDialog() problem" New topic
Author

JOptionPane. showMessageDialog() problem

Naresh Talluri
Ranch Hand

Joined: Oct 12, 2007
Posts: 115
Hi,

I have small problem with JOptionPane. using this iam showing some message. but once we clicked OK button alert window closed and the background color changed to white.
code :

I already defined container, by using getContentPane();

JOptionPane.showMessageDialog(this,"This is alert");

can you please tell if any solutions you do have,

Thanks,
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

What's the code before and after this call? Because this alone should never ever cause a GUI change.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Naresh Talluri
Ranch Hand

Joined: Oct 12, 2007
Posts: 115
Here is the code



here onclick of any button iam validating accordingly and showing messagdialogue box with some text.
onload of application the background color is showing gray, after clicking OK button in dialog box only that part of message box area showing white.
if i given showMessageDialog(null, text); the alert box is showing in the center of window to avoid that one i had given "this" as first argument in showMessageDialog();
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

Naresh Talluri wrote:

Ehm, wouldn't that be the cause of the white background?
Naresh Talluri
Ranch Hand

Joined: Oct 12, 2007
Posts: 115
it won't cause , i commented and checked , but still it is persisting.

here is my total code.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

Naresh Talluri wrote:

You forgot the call to super.paint(g):
Naresh Talluri
Ranch Hand

Joined: Oct 12, 2007
Posts: 115
Hi,

Thank you for the solution but if i call this method i can't able to draw the lines , each and every time it is overrite the existing draawing , can you please
give me any other solution.

Thanks,
Naresh T
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

Store the lines and draw them all each time instead.

You can use a Rectangle of which the x,y pair denotes the start point and the width,height pair denotes the distance; the end point is then x + width,y + height.

Also, what's the deal with that "jp.add(jp);" line? Adding a panel to itself? That's not going to work.
Naresh Talluri
Ranch Hand

Joined: Oct 12, 2007
Posts: 115
Hi ,

Thanks again for your solution , it is impeccable but it is not containing the previous drawn lines, and each time it is drawing newly,
can you please tel me if you have any solution.

Thanks again for your time.

Thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

Ah yes. My mistake. The rectangles are wrong; they should be as follows:

Also, I noticed you're calling super.paintComponents from paintComponent. Surely that s is wrong.
Naresh Talluri
Ranch Hand

Joined: Oct 12, 2007
Posts: 115
Hi Rob,

It is extremely working well, thank you alot
I have small problem while drawing lines, iam trying to draw slowly by using Threads, can you please let me know how i can proceed ,
I tried with Runnable interface but iam not successed, can you please give some code snippet to how i can follow.

I really appriciate you , thanks for your time.

Thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

When working with threads and Swing, use SwingWorker. In short:
One warning: the SwingWorker may gather objects sent by multiple calls to publish. For instance, when you called publish(b1) and publish(b2, b3), the List in process may contain only b1, only b2 or b3, or all three.

In your case you could try this as follows:
- use Rectangle as B
- in doInBackground, you loop for the length of your line
- for each loop iteration, you create a new Rectangle that represents the part that will already be drawn
- you then publish that Rectangle
- in process, you take the last element which represents the last line piece (the other ones will be discarded)
- you replace the last element of lines with that element
- you repaint

In (semi-pseudo) code, for right only:
How it's called:
Note that you will need to disable and re-enable your buttons, or you will have race conditions.

You can make one SwingWorker class for each direction, or maybe make this one work for all directions.


As a final exercise, you can make it a bit more efficient: instead of creating new Rectangles each time, only publish the changed width / height, then update the Rectangle in lines instead of replacing it. Your SwingWorker class would extend SwingWorker<Void,Integer>.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JOptionPane. showMessageDialog() problem