• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java and Swing help...

BCYL

Diamond Member
I am writing a Chess game using Java and Swing... However there is this one problem I have...

At the bottom of my game, I have a status bar which tells users about the currently state or program, and other things... I used a JTextArea for the status bar... this bar has to be scrollable too so users can look back at what happened...

I used a ScrollPane to make the JTextArea scrollable, like this:

new JScrollPane( statusBar, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER)

And whenever I want to output new strings into the status bar I just append it to the JTextArea...

My problem is, when I add new stuff to the status bar, the JTextArea does not automatically show the newly added strings... instead users have to scroll down everytime to view the new strings... is there a way to make it so that the newly added strings are visible automatically?

I tried searching for documentations on this at Sun's website... but no luck... anyone know?

 
Chess game with Java? What an idea. I see you are going in for programming experience not speed.
I have always wondered what it will be like to program a chess game in Prolog.
Nope, can't help you...
 
It's a software engineering project from school... we have to do this formally, like write all the proposals and design documents, user manuals etc... But they don't teach us Java, saying we have to learn it on our own cuz that's what the real world is like... So I just picked up a book and start reading...

I have finished the whole project except for this minor problem...

The strange thing is, I downloaded some code from Sun which also has one of these status bar and ran the code... their status bar does scroll down by itself... But when I compare their code to my code they are almost the same... Don't know why mine doesn't do it...
 
hehe.....I got really lucky with my CS class and I only had to do checkers instead of chess 🙂 But in regards to your question, can't you just append the string you want at the top of the text area to the beginning of the string of everything else in the text area, and then use the symbol for a carriage return ( \r I think) and that would stack everything one on top of the other. For example: make your string you want to add: string1 and the current text in the textfield string2. Then you can do something like string2 = string1 + \r + string2; I haven't tried it out myself cause I have much homework, but I think that might work for you.

-Tom
 
Back
Top