two Java GUI problems - please help
Hi all
I've programmed a relay chat system in Java. Just having two GUI-related problems with the chat client itself.
Problem #1 : I can't get the chat windows to scroll as new text appears in them. The scroll bar does appear when it needs to, but it remains at the top of the box (but grows smaller as more text is appended) ...so the newly appended text is hidden unless you scroll the scrollbar further down yourself.
This is what I'm doing:
I have a JTextArea for the text, then I have a JScrollPane to which I've added the JTextArea.
Then I've added the JScrollPane to (the contentPane of) the JFrame.
I have the vertical-scroll-bar policy of the JScrollPane set to ALWAYS.
I've also set the viewport of the JScrollPane to my JTextArea.
How do I get the scrollbar scrolling to keep up with text being added to the chat window?
Problem #2
I'm using JFrames for the chat client windows. I want to prevent the chat client user from re-sizing the windows. How do I do this??
apcxpc
Junior Poster in Training
55 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
stupidenator: Thanks for that! I searched the JFrame API for the word 'resize' and nothing came up, so I was at a loss. :cheesy:
paradox814: I did that, as I've mentioned up there. It just didn't work.
apcxpc
Junior Poster in Training
55 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
remember that JFrame is derived from Frame which derives from Component (or something like that), many core methods are inherited from a parent class.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
yep. Thanks jtwenting. Remember you helped test my chat system? ... :cheesy:
Any idea on the scrollable chat windows? A chat client with non-scrollable windows is... pretty much a disaster.
apcxpc
Junior Poster in Training
55 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
JScrollPane is your friend :)
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
From the top of my head, you should set the caret position after you update the text :
jta.append("Some text!");
jta.setCaretPosition(jta.getText().length()); Have fun.
hi...
I tried this. It seems to have helped just a little, because instead of never showing new text, the scroll pane now remains just one text line behind i.e. the newest line of text appended is always hidden.
I need the scrollpane to keep up with the newest line of text. What to do??
jwenting, spill it. :cry:
apcxpc
Junior Poster in Training
55 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
Sorry, my bad. I seem to have added the code to one append point and not the other. oops.
The point being... the original code worked! Thanks DeepZ. Much appreciated.
apcxpc
Junior Poster in Training
55 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
The original code as in...
jta.append("Some text!");
jta.setCaretPosition(jta.getText().length());
.. not my original code. :mrgreen:
apcxpc
Junior Poster in Training
55 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
don't hijack other peoples' threads, post your own.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337