Welcome to the JavaTM Developer
ConnectionSM Tech Tips. This special
edition covers debugging.
Ctrl-shift-F1 in Swing Applications. As a programmer, you
may have had the experience of one of your customers having problems with the
GUI of a Swing application you developed in JDKTM
1.1 or later. The application seems to work fine on your machine, but you need
to see what's happening on your customer's machine. Unfortunately, the customer's
computer doesn't have the ability to do screenshots, and you can't diagnose the
problem.
So next time you want to solve this kind of GUI problem, try this tip:
ask your customer to type ctrl-shift-F1. Typing ctrl-shift-F1 displays the
GUI hierarchy shown below. The toString method is called on each component
in the GUI tree. Sometimes a component will have a paramString(), which is
also called for that component's own special diagnostic string.
InternalDialog[dialog0,1,0,189x63,layout=
java.awt.BorderLayout,
modeless,title=Demo]
com.sun.java.swing.JRootPane[,5,25,179x33,
layout=com.sun.java.swing.JRootPane$RootLayout]
com.sun.java.swing.JPanel[null.glassPane,0,0,179x33,
hidden,layout=java.awt.FlowLayout]
com.sun.java.swing.JLayeredPane[null.layeredPane,
0,0,179x33]
com.sun.java.swing.JPanel[null.contentPane,0,0,179x33,
layout=com.sun.java.swing.JRootPane$1]
com.sun.java.swing.JDesktopPane[,0,0,0x0]
com.sun.java.swing.JPanel[,0,0,179x33,
layout=java.awt.FlowLayout]
com.sun.java.swing.JComboBox[,5,5,169x23,
layout=com.sun.java.swing.plaf.metal.
MetalComboBoxUI$MetalComboBoxLayoutManager]
com.sun.java.swing.plaf.metal.MetalComboBoxButton
[,0,0,169x23,
layout=com.sun.java.swing.OverlayLayout]
com.sun.java.swing.CellRendererPane[,0,0,0x0,hidden]
//the following 2 lines of code must be
//typed on one line
com.sun.java.swing.plaf.basic
.BasicComboBoxRenderer$UIResource
[,-143,-16,0x0,invalid]
How can you decipher this hierarchy? Well, it doesn't matter if you're
using Swing or the base AWT, because all the components inherit from
java.awt.Component. This results in the toString method of
java.awt.Component being called for each component in the hierarchy.
The first field inside the [ ] block is the name of the component. The
name is often blank because super() is called to initialize the component
without a parameter. Next come the x and y coordinates followed by the
width x height pair.
If the component is either invalid, hidden, or disabled, then that case is
noted as the next value in the block. If the component is valid, visible,
and enabled, you don't see this parameter.
As noted earlier, some components have a paramString method for custom
diagnostics. Common paramString outputs you might see are the layout
manager class string if the component is in fact a Container, and the mode
and title values if the component is a Dialog (or JDialog). The beginning
of the example shown above, InternalDialog, has both of these paramStrings.
So, with this information you can see if the components are visible, check
which components are possibly due for a repaint (invalid), and see if
components like JButton can be pressed (enabled).
Using Diagnostic Classes with JDKTM
1.2 If you've worked with JDK 1.1 releases and earlier, you may
that you can substitute diagnostic or patched classes for the default JDK
classes by adding them to the -classpath parameter when you run your application.
You can still use this feature in JDK 1.2 with a little reconfiguration.
The parameter you need is the -Xsysclasspath option. And in addition to
your own classes you must specify all the classes that the Java Runtime
needs.
Here are two examples. Both use a patch.jar file that contains classes
used instead of their equivalent JDK versions.
-- On Unix
java -Xsysclasspath:patch.jar:/jdk1.2
/jre/lib/rt.jar:. myapp
-- On Win95/NT
java -Xsysclasspath:patch.jar;h:\jdk1.2
\jre\lib\rt.jar;h:\jdk1.2
\jre\lib\i18n.jar;. myapp
JavaSM
UniversitySM Education Conference.
If you're interested in learning more about Java language programming and
application development, attend the Java University Education Conference,
presented by Sun MicrosystemsTM. The
Developers Program includes three curriculum tracks: Advanced Java Technology,
the Java Programming Language for Structured Developers, and the Fast Track
Java Programming Language Certification program. Also part of the conference
is the Java University Lab room, where you can practice with Java technologies,
apply what you learn during the day's sessions, or check your email. Fully
configured, state-of-the-art workstations will be available -- or bring your
own laptop and plug in.
-- Dates, location, and registration
The Java University Education Conference will be held in two locations:
Internet World Fall, October 7 - 9, 1998 at the Jacob Javits Convention
Center, New York and at Comdex Fall, November 14 - 19, 1998, at the Sands
Expo & Convention Center, Las Vegas. For more information or to register,
see:
http://www.sun.com/java-university
|