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
 
Office Hours Transcripts Index

Office Hours:
Fundamentals of Swing, Part I:
March 25, 1999

Moderator (MDR): John Zukowski

MDR-jaz: Welcome to today's office hours for the online Swing tutorial. My name is John Zukowski with the MageLang Institute. We'll get started at the top of the hour for an hour of Q&A on Swing and the tutorial.

If you are new to the moderated forums here, your questions appear in a queue and I post one at a time, inviting the questioner to provide additional information.

If you are not familiar with the tutorial, it is available at the JavaTM Developer ConnectionSM (JDC) at:

Nestor: I have a question about JavaTM Runtime Environment (JRE), that just wouldn't work. HELP!

MDR-jaz: Welcome Nestor, what's the problem?

Nestor: I spent 2 weeks developing an application, and when I am ready to ship it, JRE refuses to run it. Java runs it ok, but JRE says "Class not found," and aborts.

MDR-jaz: I need a little more detail than that.

Nestor: Like what?

MDR-jaz: Did you install a JRE? What version? Did you set CLASSPATH? What class?

Nestor: I have Java Development Kit (JDKTM) version 1.1.6 installed and running. In installation manual it says not to set CLASSPATH. Class Rman, which is the main class in my application.

MDR-jaz: Is CLASSPATH set to something by another application?

Nestor: I know my JDK version is not the newest, but the newest JRE refuses to run with the same error.

No. CLASSPATH variable does not exist. I always make sure nothing sets it.

MDR-jaz: Without seeing your specific environment, I don't have a clue. Can you try to upgrade to the latest version?

Nestor?

Well...while nestor is downloading the new JRE/JDK, let's move onto a question or two related to Swing.



franceslui: Hi! I asked this question last week, but I didn't make this question clear. So, I would like to make it clear and ask again. Here is the question: Is it possible to make a JComponent enabled and cannot let users change its value? For example, if a checkbox has its value true, it is still enabled but the user cannot change it to false. I don't want to make it disabled because it is hard to read and it looks like insignificant when it is disabled. Same thing is for all the other JComponents such as JTextComponent and JRadioButton. I need to have components that are enabled and cannot accept input because my users want to have an option to make components read-only while they are only reading data in a frame.

Second question: Why are check boxes and radio buttons opaque by default? I would like them to be transparent because some of my frame's background is not gray and I have to make each check boxes and radio buttons in these frames transparent so that these components do not have a gray background. Will they be transparent in the future API?

Third question: How do I send an email to users after they click a button in an applet? My web site is hosted by an ISP and it is probably that the web server and the mail server are not in the same machine.

MDR-jaz: Welcome back frances.

Please post questions separately next time, makes things a little easier. I'll start from the bottom up though. An untrusted/unsigned applet can only communicate with the machine that applet came from. If your web server an email server are separate machines, an applet cannot send mail.

Regarding check boxes and radio buttons not being opaque by default...that was a decision made by the Swing team. If you don't like that behavior subclass them and make transparent the default.

Franceslui, there is no built in support for the behavior you desire. YOU have to create it yourself if you want it.

I understood exactly what you were asking last week. Create a new UI. When enabled=false, use fonts of enabled=true.



bemmo: I am trying to extend the swing TextField class to implement editmask functionality. I am trying to automatically insert special characters (i.e. - decimal, comma...) in the appropriate locations without the user having to type them. Should I be trying to implement this at the data model level or in the UI?

MDR-jaz: Welcome, bemmo.

If the characters are strictly for UI purposes, then put them on the view side (textfield). If the characters are meant to be stored in the data model, put them in the Document.

For instance, if 123456789 is the Social Security Number (SSN), do you want to STORE 123456789 or 123-45-6789? If first, put dashes in at UI level, if the latter, put dashes into Document model.

bemmo: Any clue how this would be done in the UI (25 words or less)?

MDR-jaz: Probably with setText.

bemmo: setText eventually calls InputString on the data model.

MDR-jaz: Oops, that's right.

marsigme: Bemmo, is it absolutely necessary to have one continuous text field?

MDR-jaz: Another option is multiple fields, as marsigme implies.

bemmo: What do you mean?

MDR-jaz: You can have three text fields, once there are 3 characters in first, auto shift focus to second. When two characters in second, auto shift focus to third (using SSN example).

bemmo: Not the solution I was looking for, but it might work!

MDR-jaz: The other option is auto adding to document. JoeSam seems to have some opinions on this, Welcome JoeSam, please share what you think...

JoeSam: Actually I was basing it on the AWT, I'd have to check for same functionality in Swing.

bemmo: What is the functionality you are referring to?

MDR-jaz: Oh well...It's done mainly in the Document with Swing.

JoeSam: Add a KeyListener in AWT. In this case, count strokes and add mask items as you go.

bemmo: Yeah, you basically have to do the same thing in Swing...any word on whether future releases will support masks?

MDR-jaz: Which is what you do with Document in Swing.

JoeSam: Listen to jaz, he knows.

MDR-jaz: I have heard rumors of there being something, but it won't be until there is another major release.

JoeSam: lol.

bemmo: Thanks for the input.



tisom: Jaz, I am currently having inconsistent behavior between the Windows JDK 1.2 and the SolarisTM JDK 1.2. When I am entering a numeric value into a JTable and I press the ENTER key on the numeric keypad and the num lock key is active, the Windows version accepts the value but the Solaris version seems to be getting a new line and a return (maybe). Have you ever had this problem or can you think of a way around this? Thanks.

MDR-jaz: Welcome tisom.

I believe there is a different key code generated for the ENTER key on the numeric keypad.

tisom: Yes but should it not be the same under Windows and Solaris?

MDR-jaz: The only workaround I can think of is to find the Action for the regular ENTER key and assign it to whatever keycode comes back for Solaris.

Quickly looking through keycodes, I don't see a different one that stands out. Do you know what the VK_* constant is that comes back for Solaris?

tisom: How would I do that?

MDR-jaz: Attach keyListener, part of keyEvent.

Still there tisom?



dbaeli: I'm trying to extend a paragraphView in order to break line inside words with an algorithm of my own. Today I made it changing the document structure, but now I would like to do it only on display. My searches lead me to a curious getBreakLocation in swing.text.Utilities, used in paragraphView, and now I need to build a strategy for replacing this method, but before I need to know if I have a chance of success and, if not, is there an other solution. Thanks.

MDR-jaz: Welcome db.

While tisom is trying that out, let's move on to the next question...that isn't part of the tutorial. ;-)

MDR-jaz: Db, I haven't dug into that level of detail with the inside of the text document framework.

dbaeli: Sorry, but may I ask where I can find a solution?

MDR-jaz: There is a handful of articles on the text libraries at the Swing Connection (www.theswingconnection.com) from Sun Swing engineers. Not sure if that is one of the topics though.



javamatt: The Java Swing book also has really good coverage of ParagraphView and the whole text package in general...

MDR-jaz: A comment from the gallery.

MDR-jaz: I think javamatt is referring to the O'Reilly Swing book.

dbaeli: I've read many of them, but their Swing book is a little bit too thin and the Java Swing book is too.

MDR-jaz: Sorry, can't help you then. I can try to include it in an outline for Part III of the Swing course. ;-)

dbaeli: But they don't really explain how to build the structure I need, I just want to find someone able to help me a while, but maybe not now...if it's too hard.

MDR-jaz: Did you try posting something to the adv-swing mailing list?

dbaeli: This is interesting. I don't know this mailing list, have you more details?

MDR-jaz: Subscribe by sending a message to advanced-swing-subscribe@eos.dk, regular swing mailing list subscription is swing-subscribe@eos.dk

The archive of regular swing list is http://www.eGroups.com/list/swing Trying to get archive of advanced list to be http://www.eGroups.com/list/advanced-swing

dbaeli: That's fine for me, thanks a lot!

MDR-jaz: Good luck.



marsigme: I have not tried using the JTabbedPane component yet but I would like know if it is difficult to start out with?

MDR-jaz: Gee, marsigme left.

Hopefully will read transcript.

Not difficult at all marsigme. Look at the section in Part I of the Swing tutorial at the JDC.

Next.



bemmo: Any hints on how I can speed up the population of a list/combo box. When I try to insert 500 rows from a result set, the query returns within a second or two. It then takes 20 seconds to populate the list. Any thoughts?

MDR-jaz: Welcome bemmo.

Thoughts? Redesign the user interface. I would really hate to be a user and have to scroll through 500 options to find the one I want.

Otherwise...how are you loading?

bemmo: Short of that...I am scrolling through the result set creating vectors of the data returned by the result set. I then (through an extended UI) pull out the first item in the vector to display in the list.

MDR-jaz: Have you timed how long it takes to create the stuff before it even touches the UI?

bemmo: Yeah, by stepping through the debugger. I was hoping that it would be possible to remove some of the event generation going on during the insert process until all items had been added.

MDR-jaz: If you completely create the data before you touch the UI, there is only ONE event generated.

bemmo: What is that event?

MDR-jaz: Property change event I think...or change event.

bemmo: Can I extend the list classes to prevent these while in "populate" mode?

MDR-jaz: Why are you populating one at a time?

bemmo: How else?

MDR-jaz: public JList(final Vector listData) / public void setListData(Vector listData)

bemmo: Cool, thanks!

MDR-jaz: You're welcome. Good luck.

Gee, question queue is currently empty.



bemmo: Me again. Does that setListData call just enumerate through the Vector adding one at a time?

MDR-jaz: Welcome back.

Nope. Creates a new AbstractListModel. (Which is another thing YOU can do directly). Avoids need to create second structure for list.

bemmo: Good point, thanks again!

MDR-jaz:

  public void setListData(final Vector listData) {        
    setModel (new AbstractListModel() {               
      public int getSize() { 
        return listData.size(); 
      }                
      public Object getElementAt(int i) { 
        return listData.elementAt(i); 
      }           
    } );   
  }

From the source of JList it's really easy create a custom data model for any of the Swing components.



javamatt: Do you know if there is a way to change the rendering of tree line styles in sub-trees? The Tree.linestyle client property allows change for a whole Metal tree...but I want, for example, specific sub-trees to have dashed lines, and others solid. I can either override MetalTreeUI or actually place separate JTrees inside the parent tree, but both solutions seem like hacks. Any suggestions? Thanks.

MDR-jaz: Hi again matt, I saw this question on the mailing lists.

I think you need to create a new TreeUI. The capabilities you want are not part of the existing UI. Not a hack. Interesting idea of nesting JTrees inside one another.

If no one else has any more questions, I want to thank everyone for coming.

javamatt: I'm not sure which would be the better solution.

MDR-jaz: I think the better solution is creating a new TreeUI as that is exactly what you are doing.

Thanks for stopping by the Swing tutorial office hours. Hopefully I was able to answer your question.

javamatt: Ok...I'll try it out...Thanks.

MDR-jaz: Do look for a transcript online soon.

[You're Welcome]

And, look for Part 2 of the tutorial soon.

Last moderator (me) signing off. The forum is now unmoderated.

No more moderator...open chat if you want.

javamatt: The text area scroll bar doesn't work in this applet.. and I can't highlight any text...plus the whole frame jumps to like 300x300 when the user list changes...John, maybe you should get your hands on the source for this.

:)

Ok...John (MDR-jaz) is gone.

Forum closed at 12:57:19, Mar 25, 1999
coffeecup

John Zukowski is a Software Mage with MageLang Institute. He is the author of John Zukowski's Definitive Guide to Swing for Java 2, Mastering Java 2, Java AWT Reference, and Borland JBuilder: No experience required. John also serves as the Focus on Java guide at the Mining Co.


Reader Feedback

Tell us what you think of this transcript.

Duke

Very worth reading Worth reading Not worth reading

If you have other comments or ideas for future articles, please type them here:


Print Button
[ This page was updated: 21-Sep-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary | Feedback | 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.