|
Question of the Week presents answers to key questions posed by the
developer community. The intent is to pass this
important, but not always easy-to-find information on to JDC members.
The questions are selected from the JDC newsgroups generally because:
they are frequently asked, they are significant or timely, or their answers are not easily
accessible.
Note: If you have a question to which you need an answer, try the
JDC newsgroups. You can read through
the existing newsgroups, or with your free
JDC membership, you can post new messages or threads.
Question of the Week
Archive
Question:
How do you ignore user input in a Swing application?
The user has just pressed a button in an application and the operation will
take some time. You want to put the application in a busy state.
How do you get the application to ignore user input?
Answer:
setEnabled(false) on the frame should work.
Unfortunately if you call Frame.setEnabled(false), the interface goes blank.
To block input without hiding the interface, try using a 'glasspane'.
You can set the glasspane visible to intercept events before they reach the underlying components.
Check out:
http://java.sun.com/docs/books/tutorial/ui/swing/rootpane.html#glasspane
which has examples of glasspane usage.
Many thanks to JDC Member, bk for contributing to this answer.
Fri Sep 11 20:56:29 PDT 1998
NAGADEW
IS THERE ANY WAY TO SAVE AN IMAGE (GIF/JPEG) FROM AN JAVA APPLET/APPLICATION?
Sat Sep 12 14:44:27 PDT 1998
sricox
useful but not immediate solution
Mon Sep 14 08:03:57 PDT 1998
fstaes
This will work if the long-lasting action gets performed in
a separate thread.
If, however, the action is performed in e.g. the actionPerformed
method itself, the events simply will be queue'd and
handled afterwards.
In that case, one can explicitly empty the event queue
at the end of the actionPerformed method.
Mon Sep 14 08:36:19 PDT 1998
jeffraby
Is there a problem with the JDK1.2 beta release? I keep getting the same error message whenever I try to run a Java program after I've compiled it. Message reads- Exception in thread "main" java.lang.NoClassDefFoundError: bigdebt
Tue Sep 15 01:53:48 PDT 1998
nanite
I like the way java class names are related
to the real world. It make things easier to remember.
Tue Sep 15 03:42:59 PDT 1998
Balaji123
this is a good tip
Tue Sep 15 04:53:34 PDT 1998
vusonlam
(How) can I get Java Plugin Activator with JDK 1.1.5
or 1.2 ?? (in plugin with 1.1.6 don't work awt modal
dialogs)
Wed Sep 16 06:52:56 PDT 1998
Radu3000
How can I make the Swing Border transparent?
Wed Sep 16 08:43:10 PDT 1998
Anonymous
What is happening with JAVA?
PCWeek has one of your execs saying that
server-side Java is the only viable part of
Java development? Has Sun changed its support for the language???
Wed Sep 16 10:20:17 PDT 1998
pzhou
How do I print a image displayed in a JFrame
using the PrinterJob and implementing the
Printable in JDK1.2beta4?
Below is a test which takes for more than 5mins to
print a <100KB gif. What's wrong here?
import java.awt.*;
import java.awt.print.*;
import java.net.*;
public class Print3 extends Panel {
int width = 300;
int height = 400;
public Print3() {
try {
System.out.println("Retrieving Image");
URL oImageURL = new URL("http://some.URL.com/some.gif");
Image oImage = (Image) getToolkit().getImage(oImageURL).getScaledInstance(width, height, Image.SCALE_DEFAULT);
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(oImage, 0, width, height);
tracker.waitForID(0);
if (tracker.isErrorID(0)) {
System.err.println("Load Error");
System.exit(1);
}
System.out.println("Retrieved Image");
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(new T1(oImage, this));
pj.print();
} catch (InterruptedException e) {
System.err.println("Interrupt");
} catch (MalformedURLException e) {
System.err.println("Bad URL");
} catch (PrinterException e) {
System.err.println("???");
}
System.exit(0);
}
public static void main(String[] args) {
new Print3();
}
}
class T1 implements Printable {
Font fnt = new Font("Helvetica-Bold", Font.PLAIN, 48);
Image oImage;
Panel oPanel;
static int i = 0;
public T1(Image poImage, Panel poPanel) {
oImage = poImage;
oPanel = poPanel;
System.out.println("T1");
}
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
if (pageIndex > 0) {
return Printable.NO_SUCH_PAGE;
}
System.out.println("Printing page " + pageIndex);
g.setFont(fnt);
g.drawString("Test #6", 100, 100);
g.drawImage(oImage, 200, 300, oPanel);
System.out.println("Success:" + ++i);
return Printable.PAGE_EXISTS;
}
}
Wed Sep 16 14:29:17 PDT 1998
jonross
For some debugging / logging code, I'd like to get the class/method name that called the debug code.
The best way I can think of, is to generate an exception, dump the stack, and parse it.
Is there a better way? a hook in the debugging APIs in 1.1.6? any way in 1.2?
Thu Sep 17 01:58:48 PDT 1998
DrUrbas
Very helpful!! Thank you!
Thu Sep 17 11:17:47 PDT 1998
gorjan
When, if at all, can we expect a Linux version of the SunSoft JDK?
Thu Sep 17 14:11:35 PDT 1998
MalcolmD
Can I have the question of the week mailed to me in the same way the Tips are mailed
Sat Sep 19 06:57:50 PDT 1998
amitabh_mehta
Thanks !!
Your tip saved my day.
Sat Sep 19 10:26:40 PDT 1998
kien_ong
How do I use Java language to do some hardware interfacing?
What are the necessary tools that I must have?
Sat Sep 19 10:27:01 PDT 1998
kien_ong
How do I use Java language to do some hardware interfacing?
What are the necessary tools that I must have?
Sun Sep 20 07:06:30 PDT 1998
wpfeiffer
How do I subclass JTextField to convert all input (whether keyed in, or pasted in) to all UpperCase?
THE INFORMATION PROVIDED IN THE JAVA DEVELOPER'S CONNECTION IS PROVIDED 'AS IS'
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
LIMITATION THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR, AND
NON-INFRINGEMENT.
THIS INFORMATION IS PROVIDED AT NO CHARGE. BY USE OF THE INFORMATION YOU AGREE
THAT NEITHER SUN MICROSYSTEMS, INC. NOR ITS LICENSORS WILL BE LIABLE FOR ANY
DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF
BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF SUN OR ITS LICENSORS HAVE BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR
LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING
LIMITATION MAY NOT APPLY.
THIS INFORMATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS.
CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN. SUN MICROSYSTEMS, INC.
MAY MAKE IMPROVEMENTS AND OTHER CHANGES IN THE PRODUCTS AND THE PROGRAMS
DESCRIBED HEREIN AT ANY TIME WITHOUT NOTICE.
|