944,116 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6635
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
May 2nd, 2005
0

two Java GUI problems - please help

Expand Post »
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??
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
apcxpc is offline Offline
55 posts
since Sep 2004
May 2nd, 2005
0

Re: two Java GUI problems - please help

I'm not sure about your first problem, I've been wondering that myself. But I do know how to solve your resizing problem...

I think that you just want to use this:

JFramename.setResizable(false);

-Nick Nisi
Reputation Points: 18
Solved Threads: 4
Junior Poster
stupidenator is offline Offline
192 posts
since Mar 2005
May 2nd, 2005
0

Re: two Java GUI problems - please help

use javax.swing.JScrollPane and then just add your text area to this
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
May 3rd, 2005
0

Re: two Java GUI problems - please help

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
apcxpc is offline Offline
55 posts
since Sep 2004
May 3rd, 2005
0

Re: two Java GUI problems - please help

remember that JFrame is derived from Frame which derives from Component (or something like that), many core methods are inherited from a parent class.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
May 3rd, 2005
0

Re: two Java GUI problems - please help

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
apcxpc is offline Offline
55 posts
since Sep 2004
May 3rd, 2005
0

Re: two Java GUI problems - please help

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
Black Knight is offline Offline
25 posts
since Mar 2005
May 3rd, 2005
0

Re: two Java GUI problems - please help

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.
Reputation Points: 13
Solved Threads: 0
Light Poster
DeepZ is offline Offline
27 posts
since Sep 2004
May 3rd, 2005
0

Re: two Java GUI problems - please help

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
Black Knight is offline Offline
25 posts
since Mar 2005
May 3rd, 2005
0

Re: two Java GUI problems - please help

JScrollPane is your friend
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

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.
Message:
Previous Thread in Java Forum Timeline: i need help with arrays
Next Thread in Java Forum Timeline: methods





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC