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 JComponent
s 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: