Bill Liteplo

Ranch Hand
+ Follow
since Oct 16, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Bill Liteplo

There are probably other ways, but I think you can do:
(assuming your JTextArea is in a JScrollPane)

I don't remember if JTextPane.setCaretPosition() will automatically scroll the scrollpane, but you can try that as well.
Bill
21 years ago
This depends completely on the LayoutManager you are using (e.g. BoxLayout, BorderLayout, etc.).
Check out Sun's tutorials on Using Swing Layout Managers on their website.
Bill
21 years ago
Good question.
I would suggest looking in the Swing code for JFileChooser at the method createDialog. It creates a JDialog and puts the file chooser panel into it at BorderLayout.CENTER. When you call showOpenDialog this calls showDialog and, in turn, createDialog.
So, either take your JFileChooser and put it inside a JDialog that you create and control (possibly copying code from Swing), or create a class (or inner class or anonymous class) that extends JFileChooser and override the createDialog method so that it sets the JDialog to be non-resizable.
Use setResizable(false) from java.awt.Dialog on the JDialog.
For example, (this is copied from jdk1.4.1):

I haven't tried this code but my guess is it will work.
Bill
21 years ago
Sorry for the blantant plug for my company's product, but the Oculus Layout Builder is really a great tool for super quick GUI building.
It uses a custom layout manager, so you would have to include a provided jar file when you run the code, but the layout manager really blows the other ones away. It is incredibly smart about stretching and sizing components. It is really easy to build GUIs that look and resize the way you want. You build the GUIs visually with drag and drop, and the generated code is very well organized.
It's not a full IDE, but it excels at making GUIs quickly and nicely. We use it internally when designing storyboards and GUIs for our other Java-based products, so I recommend it from personal use.
You can find out about it at Oculus Layout System.

Bill
21 years ago
A few suggestions,
I find it useful to separate the actions from the menu items/buttons that invoke them. So you can define a simple menu and fill it up, but create the menu items with actions, and they will be hooked up fine, including enabling/disabling.
We have separate classes for each high-level action (such as Cut/Copy/Paste, etc.) that are non-static, but instantiate a static instance of each within the class, and provide a method to get this static instance. E.g.

Additionally, we have a concept of global selection which allows us to get the thing that is currently selected in the application, regardless of which window it is in, and act on it. The global selection adapter is also static.

If your main frame can keep track of your internal frames, that sounds like a good place to do the management of linking your classes (non-statically). If not, you can have your internal frames manage themselves with a static reference. No harm in that.

It all really depends hom complicated your application is. All the stuff I mentioned before is after years of more local (non-static) management of actions and windows, which was fine for a while.
Hope this doesn't confuse you more.
Bill
22 years ago
I agree with the caching idea.
AFAIK, JTables continually ask for getValue from the renderer as you move your cursor over them. JTrees, JLists, do not.
Bill
22 years ago
Change the original data (held in some Vector, array, etc.) from which your ListModel gets its data, then call fireContentsChanged on the model (must inherit from AbstractListModel).
There are other ways.
Bill
22 years ago
Or frame.show()
Bill
22 years ago
How are you adding data to the JList?
I think the problem may be more with your layout manager than your component or data. What layout manager are you using?
For example, if you used BorderLayout and added the JList, in a JScrollPane, to your panel at BorderLayout.CENTER, it should stretch in both directions.
Bill
22 years ago
Try setPreferredSize. When doing layout, prefer methods defined in swing components (e.g. javax.swing.JComponent) over those in awt components (e.g. java.awt.Component).
Now, don't expect all layout managers to respect the preferred size of a component. You may want to use setMinimumSize and/or setMaximumSize, if that is really what you want to do. Don't use those just to set the initial size.
Bill
22 years ago
You should create your own ListModel (for example, extend DefaultListModel) and set that as the model of your JList.
When I create a JList, I get a big empty box. I can't type in it (it is not editable, which was one of my questions). If you want to edit the data on the fly, you should set the list cell renderer to return a JTextField instead of the default (which is an uneditable JLabel). This will make it editable.
Alternatively, you can use a JTable with one column, in which case you should set up a TableModel to broker your data.

Having fun yet...?
Bill
22 years ago
A couple comments:
I would use Swing over AWT, definitely.
If you are creating your GUI by laying out components (and maybe moving them around), use JLabels. You can call setFont and setForeground on them for size and color.
If you are doing animation by customizing the painting (display) of a panel (JPanel), use the setColor method on Graphics2D, as well as a host of other things you could do there.
How you do the animation depends on how complicated your GUI needs to be. Probably, however, you should control it with a System time-based counter running in a separate thread that updates your display every X milliseconds.

Bill
22 years ago
No, but my company's created one that's less simple.
We used a JTree and a JTable side by side and use various listeners to keep the table listings in synch with the expansion and collapsing of nodes in the tree.
It's gotten us a long way, although we've moaned and groaned along the way, somewhat due to complications related to our tree table, but largely caused by the complexity of our system, not just the GUI component.
Bill
22 years ago
Well, JList is your man.
Bill
22 years ago
Oculus Layout System version 1.0.3 released October 25, 2002!

What's New in 1.0.3:
* JSplitPane support added to Builder
* Background/Foreground colors settable from Builder
* Characters that are not allowed in Java identifiers are not permitted in
variable names or generated class names
* "Opaque" property of JComponents added to Builder
* Minor bug fixes
* Better optimization of saving files

(It's like I'm having a conversation with myself )
22 years ago