Harold Lime

Ranch Hand
+ Follow
since Jul 20, 2009
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 Harold Lime

Your code appears to throw a NullPointerException on by line 105 (which, IMO, should be split over two lines).

Try adding some System.out.println() statements so you can see where your code gets to - I think you'll notice that something important is never happening.
10 years ago
I've read tutorials on I18N and have begun implementing it in an application I'm writing.

I've got the basics working, the user selects from a JComboBox, then using the Observer pattern I loop through a list and let them know the language has changed.

I'm using MVC, am I right in thinking that the translation code would be best placed into the Controller level (of which there will be many). So instead of hard-coding the text to appear on labels it would be replaced by several methods called from the controller to set this text based on a ResourceBundle

I might be wrong but I think that with the size of the application (it's a sports management simulation game) that it will be better to only make I18N changes take effect as and when a panel is next shown - the main reason for this the game will have a sort if 'inbox' of messages - translating possibly hundreds of such messages could take a while?

Can anyone comment on whether I'm on the right lines?

If anyone has got tips or recommendations for books / articles to read that cover such things then I would be grateful.

One idea I've had, not sure it's a good one, is to create a wrapper class around a ResourceBundle to hide the re-reading of properties files. Instances of then this class could be passed into the controller who could read as and when instructed to do so - it would not need to keep a track of the locale, bundle name, class loader etc. it would just need to access the class again when informed to do so.

Any thoughts / comments appreciated.


10 years ago
Brilliant! I knew would be simple.

11 years ago

I've got the following running fine one a Windows machine:

But the following does not work in Linux.

I'm fairly new to Linux so I've probably missed something simple.

Can someone tell me what I'm missing?
11 years ago

I had set the background of the one of JPanels involved to new Color(0,0,0,0) rather than setOpaque(false).

Thanks for the help.

12 years ago
I've got a bit of a problem, I'm using a transparent JTable, when I change the data on it I can still see the old value that was in the cell before.

The only way I can get rid of it (so far) is to resize the frame, so what methods are called when a frame resizes?

I've tried invalidate(), validate() and doLayout() on the contentPane but none of them are helping.

For now I'm stuck using:
frame.setSize(frame.getWidth(), frame.getHeight() + 1);
frame.setSize(frame.getWidth(), frame.getHeight() - 1);

There's got to be a better way.

Any help greatly appreciated.


12 years ago

David Newton wrote:@Harold: Please be very careful when providing complete or even partial solutions. One of our goals here is to get people to do all of their own work, experience their own triumphs and failures, learn how to learn, and so on. I'm leaving your code (someone else may not), but it's on the edge of what I'd consider "too much information". (I'm also a bit more draconian about this than some here.)

Fair point, although it's really a rejigged (and condensed) version of the code originally posted - I didn't actually add anything.
12 years ago
I'd start again, maybe with the code below, I think that all those switch statements are sending you in the wrong direction.

And as I said earlier, the code should probably be doing something like:

- Read input (done)
- Is it a number? (done)
- Is it the specified range? (easy)
- Is is a 3 digit number? (easy)
- Does it end with a number below 21? (easy, why is this important though?)

12 years ago
The build is successful but it does not run.

I've removed what I first wrote.

Check this: http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html to see how you might go about getting input from the user.
12 years ago
The code you have is overly complicated IMO.

I'd break down how you would do this on paper first, then figure out how to do that with Java.

Something like:

- Read input
- Is it a number?
- Is it the specified range?
- Is is a 3 digit number?
- Does it end with a number below 21?

Or you could just create a 1000 element array and fill it with all the answers.
12 years ago

Thanks for the help guys.
12 years ago
I'm definitely missing something...

I've look into that, and run this code:

But I still can't figure out how to make it do what I want.

Maybe I'm using a JPopupMenu for something it isn't suitable for?

Basically I want a JButton that works in the same way a JMenuBar. 1 ckick shows the menu, 2nd click hides it again. Clicking anywhere other than the menu should hide the menu also.
12 years ago
This seems like it should be really simple but I just can't get it to work.

I want a JPopupMenu to appear when the user clicks on a button.

I then when the menu to disappear when the user clicks anywhere other than on the menu.

The only problem I've got is that I'd like the same to happen when the button is clicked a second time.

Logically, to me at least, the following should work:

However, even though I can see the menu, the code always indicates it is not showing and not visible - so the menu never hides again by clicking the button.

Am I missing something?
12 years ago

Henry Wong wrote:

Harold Lime wrote:That's odd, it doesn't compile for me.

Line 63 is the problem.

That error is a known Javaranch problem -- there is some obscure issue that corrupt code, as it is being posted.


Ah, in that case I can't see anything wrong. It compiles and runs, no errors and no warnings.
12 years ago