★ wanayoo — archive 1999 http://developer.java.sun.com/developer/community/chat/CodeClinic/1997/cc1218.htmlNouvelle recherche | Portail wanayoo
Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Chat

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
Print Button
 

Code Clinic
includes questions on Swing, JDKTM, and Java Sound
December 18, 1997

Guest-Speaker (SPK): SPK-rohaly

SPK-rohaly: This is the Java Developer Connection Code Clinic. I am Tim Rohaly, from the MageLang Institute. We host these Code Clinics as well as office hours for the Swing Short Course, and have created some of the content on the JDC site.

uomini: Can you tell me if it's possible to detect double-clicks on a leaf node?

SPK-rohaly: SampleTree does answer to double click on a leaf, so you can look there. In general, Swing components are the same as other JFC/AWT components--just use the getClickCount() method of the MouseEvent that you receive in your MouseListener class.

gantzm: Any idea where I can get some information on version control and multi-programmer disciplines with the JavaTM programming language?

SPK-rohaly: Many Java IDEs these days are starting to include that stuff--for example, Visual Age and Java WorkShopTM. Or on the less integrated side, RCS works fine for Java too.

jxie: How do I put a popup menu when I click on the tree node in Swing? Has anyone tried it yet?

SPK-rohaly: I haven't tried it, but I would be surprised if the usual way of creating and showing a popup menu failed to work. Have you successfully used PopupMenu before? Are having a problem with it or just with your tree node?

jxie: I've used PopupMenu before. The problem is after I create the PopupMenu, how can I show it inside the Tree Components and just on that tree node.

rstjohn: Are there any ways to graph data using the Java language or Swing? Specifically, I would like to load and graph audio data.

SPK-rohaly: There are no graphing classes included in either the AWT or in Swing. But there are third-party class libraries that give you APIs for creating graphs and plots.

However, it's not hard to do this yourself for simple graphs or plots. You would create a data model, and your graph would be a view of the data model. You could use Swing components with their built-in MVC architecture to ease your development.

323803719: I know that we can not use Swing classes in publically distributed applications yet. Do you have any idea as to when we will be able to? In other words, have you heard when JDKTM 1.2 will be available?

SPK-rohaly: Actually, there's nothing stopping you from using Swing in a publically distributed application. You can bundle the necessary classes with your application, or if you are running an applet and the client doesn't have Swing installed, it can be dynamically loaded from your server machine just like any other pure Java classes.

As for the other part of your question, the beta version of JDK 1.2 is available right now from developer.javasoft.com.

uomini: Is there a simple way to disable selections on a node? I don't want users to be able to select the root of a tree.

SPK-rohaly: I'm not sure about disabling individual nodes, but if all you want to do is disallow selection of the root node, then you simply invoke setRootVisible() on your JTree.

jacobo: For an applet that I wrote that consists of two classes, I find the following problem. Shape is the second class.

    java.lang.IllegalAccessError: Shape
java.lang.IllegalAccessError: Shape
  at Patterns.<init>(Patterns.java:28)
  at netscape.applet.EmbeddedAppletFrame.run 
      (Compiled Code)
  at java.lang.Thread.run (Compiled Code)

I tried it in many browsers and it only gives this problem with version 3.01 of Netscape (Win95). My question: Is this a problem with the browser, or something that I can take care of?

SPK-rohaly: IllegalAccessError is thrown when you are trying to access a non-public member which you shouldn't have access to. This usually arises if you change your access specifiers in one class to make them more restrictive, but don't recompile other classes that invoke those changed members.

Is Shape declared non-public? This should usually be caught at compile time.

jacobo: It is public, and as I said, it works fine with other versions of Netscape and Internet Explorer.

SPK-rohaly: Yes, but it's possible that Netscape 4 is the only one that is doing the right thing here. Did you try appletviewer?

Without looking at your code, it is hard to say any more than I said previously. Can you post a very small snippet that exhibits the problem? It looks like you are creating an instance of Shape within the constructor of Patterns, and it is failing because it can legally access the definition of the Shape class.

kenrod: Not to sound dumb, but the JDK 1.2 beta 2 samples seem to run alarmingly slow. I'm not just talking sluggish, I'm talking unusable. I fully understand the limitations of JIT and rewriting all the controls rather than using native calls, but still, isn't this a barrier to gaining acceptance in the marketplace? Is SunTM seriously investigating speeding the Swing classes up? I'm not just talking tweaking and tuning, I'm talking a serious priority.

SPK-rohaly: I can't speak for the JDK 1.2 Beta 2, since I haven't tried it yet. But I have used the pre-beta for several months, and I certainly haven't noticed that it is slower than JDK 1.1. Can you be more specific, about what you tried and why you think it's slow?

kenrod: Regarding JDK 1.2 Beta 2, I am under the impression it is so much slower than previous versions because the examples use the JFC as opposed to native calls (i.e. a button is a JFC button as opposed to a Windows button). I understand and appreciate this overhead, but am alarmed it is so significant.

I admit I can't much vouch for anything else. All I did was download it and go through some of the examples.

SPK-rohaly: Well, the beta version of Swing is not performance tuned in any way--there is emphasis on functionality initially. This situation will improve before the final release of Swing is out. Also, I don't think there is a JIT for JDK 1.2 yet, so if you are used to running your apps using the performance pack, then yes, they will be slower.

jacobo: Yes, it works fine with appletviewer and it also works fine with Netscape 3.1 and 3.04, it only exhibits the problem with version 3.01. Could there be something related to setup in the browser? And no, I do not have a small snippet. It is weird!

SPK-rohaly: Is your Shape class by any chance an inner class? There are some known bugs with the JDK 1.1 compilers that affect access to private members from within an inner class. I don't see how it can be related to the browser setup. Since this problem seems to occur early on in your code, it seems to me you could cut out 99% of your code and get a simple test case which would fail--that would help isolate the problem and make it easy for someone to determine whether it is a Netscape bug, a JDK bug, or a problem with your code.

kenrod: Thanks, rohaly--that's good to know. Still, I think the problem goes a little beyond tweaking and tuning, and I was under the impression that JDK 1.2 came with a JIT. While we're on the subject--isn't the Java Look-and-Feel awful? It seems that Sun is deliberately not being Microsoft, to the point of making horrible looking combo boxes and tiny scroll bars, etc.

SPK-rohaly: I do think a lot of the point of the JLF is to beat you over the head with the fact that your L&F is completely customizable. That wasn't readily apparent when just the Basic L&F and the Rose L&F were present.

I think the JLF is the first of several custom L&Fs that are going to be delivered by Sun. It will probably change based on user feedback, so if you have some specific comments then send them to swing-feedback@java.sun.com. I agree, the present one isn't what I would call pretty :) But it serves as a great example of writing your own L&F. And in the end, a pluggable L&F means that you can override any part of the look that you don't like, which is a huge advantage!

Well, our two hours here is up. Please check the schedule on developer.javasoft.com for future Code Clinic dates and times. Thank you all for stopping by. See you next time.



Print Button
[ This page was updated: 21-Jun-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-2000 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.