• Post Reply Bookmark Topic Watch Topic
  • New Topic

Show labels in a panel with scolling

 
Vinicius Souza
Ranch Hand
Posts: 70
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've created a chat program, but now I need to show messages in different colors depending if the message is received or sent. I was wondering if I can use jlabel to do this but in this case I need that jlabels to scroll in a jpanel. Can you give me a hint about how to do this or maybe using a rtf ?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure.
JLabel has a method to set the foreground color. Check out the API.
1) Create a panel with the proper layout manager
2) Wrap the panel in a JScrollPane
3) Add the JScrollPane to the container
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a JTextPane it supports different styles of text. See Text Component Features for more information and examples.
 
Vinicius Souza
Ranch Hand
Posts: 70
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:Use a JTextPane it supports different styles of text. See Text Component Features for more information and examples.

I was wondering using this but I need to add each line individually one red, other blue etc and on the examples I saw in the internet and oracle documentation they read a entire file with html format. Please, can you help me ?
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to add each line individually one red, other blue etc and on the examples I saw in the internet and oracle documentation they read a entire file with html format. Please, can you help me ?


I did help you. I see you didn't read the tutorial or download the example program. The example does NOT use HTML!!!
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!