Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Torgil Zethson

Greenhorn
+ Follow
since Nov 30, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Torgil Zethson

If you look at the source code for BasicSplitPaneDivider you will see that the divider uses its own, custom layout manager. That layout manager simply ignores anything you add to the divider; it just lays out a fixed set of components that it knows about, namely the left and right button you get by default when you make the splitpane one-touch expandable.

So you will either have to provide your own layout manager, or override the BasicSplitPaneDivider class itself to acchieve what you want.
16 years ago

How does the object to be scrolled report its actual size to the JScrollPane?



Two alternatives:

1. By implementing the javax.swing.Scrollable interface;
or
2. By its getPreferredSize() method.

The first case is used by components such as JTable, JTree, and JTextArea.
The second is used, for instance, when you place a JPanel in a JScrollPane. The scrollpane will use the preferred size of the panel to decide if scrolling is needed or not.
16 years ago
One straightforward way of doing it would be to traverse the component tree rooted at the JScrollBar. The buttons will be instances of javax.swing.BasicArrowButton (I think, but use JButton to be safe), so whenever you come across a child component that is an instance of that class you add your MouseListener.

Another approach would be to override the ScrollBarUI -- the buttons have protected access in BasicScrollBarUI.
16 years ago
The best 100% Java solution I can think of is to display a popup message, asking the user not to press the Windows key again...
16 years ago
I'm pretty sure this is not possible in Java. You might be able to do it using JNI.
16 years ago
Yes, it can be done. Just store a reference to the dispatcher as an instance member of your class:

16 years ago
You can't add a MouseListener to the titlebar of a JFrame since the titlebar is not provided by Java, but by the underlying operating system. You'll find one possible workaround here:

http://forum.java.sun.com/thread.jspa?threadID=634532
16 years ago
You get a ClassCastException because your implementation of actionPerformed is faulty. You can certainly use the same ActionListener for both a JButton and a JComboBox, but you must be careful when you implement it:




Alternatively, if you don't want to keep member variables pointing to your button and combobox:

16 years ago
In the first line of your actionPerformed method you successfully cast the source of the ActionEvent to a JButton. On the line where you get the ClassCastException you try to cast the same source to a JComboBox. The source of the ActionEvent can't be both a JButton and a JComboBox, so you will have to get to the JComboBox some other way. Maybe by keeping a reference to it in a member variable?
16 years ago