Date: Thu, 10 Sep 1998 01:01:17 GMT From: JDCTechTips@sun.com Subject: JDC Tech Tips, Special Edition To: JDCTechTips@sun.com -WELCOME- to the Java(sm) Developer Connection(sm) Tech Tips. This special edition covers debugging. The JDC Team- J D C T E C H T I P S TIPS, TECHNIQUES, AND SAMPLE CODE * Ctrl-shift-F1 in Swing Applications * Using Diagnostic Classes with JDK(tm) 1.2 * Java(sm) University(sm) Education Conference - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - T I P S , T E C H N I Q U E S , A N D S A M P L E C O D E 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 JDK (tm) 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=De mo] 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.F lowLayout] 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.pla f.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] com.sun.java.swing.plaf.basic.BasicComboBoxRenderer$UIResource[,-1 43,-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 JDK(tm) 1.2. If you've worked with JDK 1.1 releases and earlier, you may know 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 JAVA(sm) UNIVERSITY(sm) EDUCATION CONFERENCE. If you're interested in learning more about Java language programming and application development, attend the Java(sm) University(sm) Education Conference, presented by Sun Microsystems(tm). 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -- NOTE -- The names on the JDC mailing list are used for internal Sun Microsystems(tm) purposes only. To remove your name from the list, see SUBSCRIBE/UNSUBSCRIBE below. -- FEEDBACK -- Comments? Send your feedback on the JDC Tech Tips to: JDCTechTips@Sun.com -- SUBSCRIBE/UNSUBSCRIBE -- The JDC Tech Tips are sent to you because you elected to subscribe when you registered as a JDC member. To unsubscribe from JDC Email, go to the following address and enter the email address you wish to remove from the mailing list: http://developer.java.sun.com/unsubscribe.html -- ARCHIVES -- You'll find the JDC Tech Tips archives at: http://developer.java.sun.com/developer/technicalArticles/TechTips/ -- COPYRIGHT -- Copyright 1998 Sun Microsystems, Inc. All rights reserved. 901 San Antonio Road, Palo Alto, California 94303 USA. This document is protected by copyright. For more information, see: http://developer.javasoft.com/developer/copyright.html This issue of the JDC Tech Tips was written by Calvin Austin. JDC Tech Tips, Special Edition September 9, 1998