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??
I had exaclty the same problem when i made a chat system for uni using a JEditorPane in a scroll window, its one of those problems which is really annoying. Im not sure if I actually fixed it but i know you can do it as some of the other students ones worked (but a lot didnt). Have you tried anchoring it to the bottom of the scroll pane or something similar, might have something to do with setEditable aswell. if the text area is editable it might not scrol properly, it may work correctly if it isnt editable, just a few ideas.
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.
I remember trying that in the app i wrote, i dont think it will work, as the caret position can be on the text area but not necessarily in the view. If it does work it would be interesting to know fo rthe future.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.