Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JLabel setText showing as ...  RSS feed

 
Rahul Chhabra
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to dynamically change content of JLabel, using setText method.
However, if I use setBounds method and setText more than that of width assigned it is coming as ...

How during runtime, I can find out JLabel text is displayed as ... (instead of full text) and increase its width accordingly ?

Could anyone please help me
 
Rob Spoor
Sheriff
Posts: 20895
81
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to resize your JFrame. Usually you can simply call pack() and be done with it, but since you have a null layout manager you'll need to recalculate the size and set it manually. One hint: use jl.getPreferredSize() to get the size the JLabel needs to display its contents fully.

Also, you should read Concurrency in Swing. While it is forgivable to write GUI code in the main thread until you start the EDT, you should definitely not do so afterwards. Otherwise you will run into threading-related problems eventually, because your main thread and the EDT both try to access the same object (the JLabel).
The EDT is usually started when you show your first window (if I'm wrong here I'm sure Pete, Darryl or Rob C will correct me).
 
Rahul Chhabra
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob,

It works
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!