Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!

alex earnshaw

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

Recent posts by alex earnshaw

Ok great, didn't realise.

I also have the same problem with JButton though - how to tell if the user clicks it or if I call doClick() in my code? Is there something in the ActionEvent that would tell me?

13 years ago
Hi all

I have a JTextField which I have added an ActionListener to. Is there any way I can tell whether the call to actionPerfomed() has been triggered by the user entering text and pressing Return or by a call to setText() in my program?

I only want to do something when the user edits the field not when I change the text programmatically? Any suggestions greatly appreciated...
13 years ago
I am using a JComboBox as an editor in a JTable, and am having a problem with the ItemListener. I have the combo set up so that the user has to double click on the cell before the combo will open (using setClickCountToStart method on DefaultCellEditor).
According to the swing tutorial, a JComboBox will fire two itemStateChanged events when a new item is selected in a combo and it will not fire any itemStateChanged events if the same item is selected.
In my combo, when you double click, the combo opens showing the drop down list, when you click again (without moving the mouse) it closes. The selection in the combo is the same as it was before you double clicked. But still the itemStateChanged event is being fired!!!
Can anyone tell me why this happens and/or how to fix it? I only want to do something when the selection actually changes....
Here is a code extract:

Thanks in advance!
13 years ago
Got that working now using the CellEditorListener!
Thanks again!
14 years ago
Yes editing the cells. Your suggestion certainly sounds like a possible solution, will definitely give it a try!
14 years ago

thankyou so much, it worked a treat! That problem was something I've been trying to solve for weeks on and off but was getting nowhere...
14 years ago
Now you've said that I think I know why it is happening...I am actually using a JTreeTable (example downloaded from the Sun Swing tutorial) so I presume that is what is causing the problem, i.e. the JTreeTable is a JTable with a JTree as a renderer for the first column so the entire table row is seen as the node therefore any edit to the row (including an expansion or collapse) is seen as a node change.
I still don't know how to get around it though!
The JTreeTable code can be got at JTreeTable article
14 years ago
I am using JComboBox as an editor in a column in a JTable. At the moment whenever I click on one of the cells in this column the combo immediately drops down and shows the options.
Is there some way I can stop this happening unless the user double clicks on the cell?
14 years ago
Hi there
Is there any way to tell what has caused a treeNodesChanged to be called?
I have a JTree which I have added a TreeModelListener to. The treeNodesChanged is being called in 2 situations:
1) when a tree node is expanded/collapsed, and
2) when a node is edited
I only want to take action when the node is edited, so how can I tell - is there something in TreeModelEvent that would tell me?
14 years ago
How can I disable individual rows in my JTable?
I am using isCellEditable to make all the cells in the row uneditable, but I also want them greyed out...
I have tried using getCellRenderer to get the renderer for the cells in the row and then call setEnabled(false) on the renderer - but this makes all the cells in the whole table greyed out!
Can anyone tell me where I'm going wrong?
14 years ago
Hi all
I am modifying a C++ application in order to expose a public interface to some of it's functionality. The clients using this public interface will be in C++ or Java.
The options for the public interface which have been suggested to me are
CORBA (Orbacus orb which supports Java and C++ mappings)
Can anyone give me some pros/cons for using both of these. The interface I'm exposing won't be anything complex but it does need to be secure, i.e. over SSL. Also I don't want to mandate that clients use particular ORBs etc, i.e. I want to avoid any interoperability issues.
Also, would it be an option (or even a good idea) to use JNI on the server side - e.g. if I go with corba I would have a corba server implemented in java which maps the interface methods to the equivalent C++ functionaliyt using JNI. This would give me more options as to what I could use for the interface e.g. free Java ORB instead of Orbacus or even RMI (over IIOP to support potential C++ clients). Also the amount of C++ I would have to write would be minimal (I have v.little exp in C++ but lots in Java!).
Can anyone give me their thoughts on this? I'd appreciate it!
15 years ago

Originally posted by John Paverd:

As a good programming practice, I would always use the escape sequences instead of the Unicode values. I was only able to use \u0008, \u0009, and \u0022 in a char literal without compilation error.

I decided to try this out for myself...can anyone explain the result for \u000c - why does it NOT cause compile error? and why \r seems to print a backspace rather than a carriage return?

For the purpose of the exam which should we say will cause a compile error???

Originally posted by John Paverd:
\d and \l are not valid because they:
are not one of the above escape sequences
are not unicode values (do not start with \u)
are not octal values (do not start with \digit

Thanks John!
So just to clarify:
It is a compile error if the character following a backslash is not an ASCII b, t, n, f, r, ",
', \, 0, 1, 2, 3, 4, 5, 6, or 7
It is also a compile error if a char is initialised to '\u000a' '\u000c' or '\u000d' as these
are processed early resulting in a new line being started, giving

The equivalent escape sequences '\n', '\f' and '\r' compile okay as they are not
processed early. And the unicodes for backspace, tab etc all compile okay as they do
not cause a new line to be started even though they are processed early.

Is this correct? Have I got it right now?
In Study Guide Mock, Chapter 2, Exam A:

Question 7
1. class Green {
2. public static void main (String[] args) {
3. char a = '\b';
4. char b = '\c';
5. char c = '\d';
6. char d = '\f';
7. char e = '\l';
8. char f = '\n';
9. char g = '\r';
10. char h = '\t';
11. char i = '\\';
12. char j = '\"';
13. char k = '\'';
14. }
15. }

What is the result of attempting to compile and run the program?
a. Compiler error at line 3.
b. Compiler error at line 4.
c. Compiler error at line 5.
d. Compiler error at line 6.
e. Compiler error at line 7.
f. Compiler error at line 8.
g. Compiler error at line 9.
h. Compiler error at line 10.
i. Compiler error at line 11.
j. Compiler error at line 12.
k. Compiler error at line 13.
l. None of the Above

Answer is given as b,c,e.
I don't understand, I thought only unicode was processed early i.e. '\u000d' would become carriage return and cause compile error - is '\d' the same thing?
Also what is '\l' and why does this cause compile error?
Can anyone give me a full list of chars which cause compile error....
Thanking you,
My understanding is that the default type of a floating point literal e.g. 10.2 is double, so if you wish to specify a float type you must use 10.2F
In the same way the default type of an integer literal is int, so if you want to specify a long you must use the L postfix.
The D postfix doesn't have any valid use that I can see, others please correct me if I am wrong...