• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using threads or there's another way?

 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in a swing standalone app i want a message to appear for a few seconds confirming user did deleted something
i'm using this code:

is there a better/smoother way of doing this?

TiA
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, once your swing application has been displayed, you are not allowed to access any of the components from anything that is not the event dispatching thread. With the exception of a few methods, like repaint(), it is not thread safe to do so.

Having a separate thread to handle the timing for changing the visibility is fine, but it is not allowed to directly manipulate the component. Take a look at the invokeLater() method of the SwingUtilities to dispatch that task back to the event dispatching thread.

Henry
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm not sure if i got it right:
my main:

my refactored code:
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
create a JFrame as private member data, create an inner class to display
the message

ex:

private class A{

public A()
{

public void paintComponent(Graphics g){}
}
}


and in your program create new instance of the private frame
and do:
.getContentPane().add(new A());
.pack();
.setVisible(true);

now you have a JFrame you can call
.setVisible(true/false);
or
.dispose();

so say you want that frame to popup when they click a certain button
you would say.

myFrame.setVisible(true);
myFrame.setAlwaysOnTop(true);

you can also set the location of the frame by

Point p = MainFrame.getLocation(); // your main clients window.
myFrame.setLocation(new Point(p.getX()+MainFrame.getLength()/2,p.getY()+MainFrame.getWidth()/2));

that would set the top left corner of your popup display message to approx.
the middle of the "MainFrame".


Justin
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well you would call the timer, then in the timer, once the
message box is visible, you would just count everytime the
timer is called, then you would .dispose() the message box
when you are out of the counter loop, and stop the current timer.


Justin
 
reply
    Bookmark Topic Watch Topic
  • New Topic