• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 15 SimpleChatClient

 
Sarah Riezen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Herro,

I'm new to learning programming in general and I've been having an issue with the SimpleChatClient in chapter 15. It connects and seems to run fine, but the JTextArea incoming doesn't show the messages being sent. Instead, it comes up in either the command, if I'm running it from there, or in eclipse's Console tab. Also the vertical scrollbar doesn't seem to show up, despite me setting it to ALWAYS visible. Either way, here's the code (don't mind my //notes, they're just to help me organize):




I've even tried to change mainPanel.add(qScroller) to mainPanel.add(incoming) to see if that was the problem, but it didn't do anything differently.

Oh, also, the server client is the ready-bake code, but it works. Basically I just don't know how to get it to print the message in the incoming JTExtArea.

Any help would be greatly appreciated. Thank you so much

-Noa
 
Paul Clapham
Sheriff
Pie
Posts: 20971
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarah Jane wrote:Also the vertical scrollbar doesn't seem to show up, despite me setting it to ALWAYS visible.


I suspect this means that the scroller component isn't visible at all. (That would explain why you don't see any text when you change the JTextArea inside that scroller.)

So, you were writing networking code, and you casually decided to throw in a little GUI to test it, and now the little GUI isn't as simple as you thought it would be. If I'm not mistaken the default layout manager is a BorderLayout. It looks like you've added all of your components into the same part of the BorderLayout, which isn't the right thing to do. But let me move this post over to the Swing forum, where people who are actually good at Swing hang out.
 
Paul Clapham
Sheriff
Pie
Posts: 20971
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
Sarah Riezen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I suspect this means that the scroller component isn't visible at all. (That would explain why you don't see any text when you change the JTextArea inside that scroller.)

So, you were writing networking code, and you casually decided to throw in a little GUI to test it, and now the little GUI isn't as simple as you thought it would be. If I'm not mistaken the default layout manager is a BorderLayout. It looks like you've added all of your components into the same part of the BorderLayout, which isn't the right thing to do. But let me move this post over to the Swing forum, where people who are actually good at Swing hang out.


I just copied what was in the book, Head First Java, 2nd Edition. I'm sure there's more efficient ways to make this stuff, but this is my first programming language I'm learning so it'll be awhile before I worry about that.

I just don't understand why it won't update in the JTextArea ><

Thanks for moving it to the right place, and for the welcome.

EDIT:
I would assume it has something to do with the incoming.append(message + "\n") on line 80, but I'm not sure.
 
Charles Burton
Ranch Hand
Posts: 39
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On lines 35 -36 try adding them to the main panel with some kind of layout. I think your objects are getting stacked on top of eachother, sorry I can't test it for you the computer I'm using doesn't have a JDK. It should look something like this.

 
Charles Burton
Ranch Hand
Posts: 39
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just copied what was in the book, Head First Java, 2nd Edition. I'm sure there's more efficient ways to make this stuff, but this is my first programming language I'm learning so it'll be awhile before I worry about that.


It's a good book, that's the one that I used to learn Java and they have a lot of really good examples in there. You just have to be careful because some of the examples are a little bit off sometimes.
 
Sarah Riezen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles Burton wrote:On lines 35 -36 try adding them to the main panel with some kind of layout. I think your objects are getting stacked on top of eachother, sorry I can't test it for you the computer I'm using doesn't have a JDK. It should look something like this.



It worked! It made the outgoing really big but I'll play around with it. Thank you so much though!
 
Charles Burton
Ranch Hand
Posts: 39
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad it worked for you, so to describe what was happening in a little more detail. Because you weren't using a layout manager all of your components were getting stacked on top of one another. Your code was actually working fine, but because the component that was displaying it was underneath another one you couldn't see it happening. I do recommend taking the time to learn GridBagLayout, it can be fairly complicated, but it really is good to know gives you much more control over how the gui looks. There is a bit of a learning curve, but once you get it, it's actually not too bad. I'v actually used it to dynamically generate filter buttons and whatnot in a nice neat grid.

http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html

Good luck!
 
Sarah Riezen
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll take a look at it today.

It didn't look like anything was over on top of anything. It looked like the JTextArea was just a white square in the GUI, getting nothing. I'm definitely interested in learning more about different layouts, since the book only touched base on "Flow" layout and "BoxLayout", just barely. I heard Java's the best language to start with, and I'm sure there are alot of mistakes to be made, but can't learn without 'em ^_^

Thanks again
 
Aidan Whitehall
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just had the same issue, and was stumped until I came across this reply http://www.daniweb.com/software-development/java/threads/405135/problem-with-chat-cliens on the DaniWeb site.

It appears to be nothing more than that the JTextArea is too large for the frame that contains it.

You can either reduce the size of the incoming JTextArea, so that:



becomes



or increase the size of the chat client's frame, so that:



becomes



and Bob's your uncle!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic