• Post Reply Bookmark Topic Watch Topic
  • New Topic

Make String display bold or italic

 
Ed Nigma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way that I can display a String in Bold (preferably) or Italics. I am using JCTable (Sitraka class). When I get certian value from the server I want to display that field as bold. Can someone help me with this?? Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

We've got a forum devoted to Swing and AWT issues; I'll move this there.
 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most SWING components will allow you to include html markup to affect their display. So if you can, you might want to try intercepting that special value if you find it, and surrounding it with <html><b> and </b></html>.

The only other way I can think of is kind of a pain in the butt. You essentially need to create your own TableCellRenderer and apply that to the particular field when that special value occurs. The crux of what you would do would be to add code like this to your JTable class (assuming that you are subclassing JTable):


and then add an inner class something like this:

Essentally, from my understanding, every table cell is rendered by a TableCellRenderer, and every table implements a default, sinple TableCellRenderer that basically just displays plaintext (I guess underlying that is a simple JLabel). If you want a table cell to appear as anything other than just plaintext, you need to create your own TableCellRenderer that returns a JComponent that will display the value for that table cell.

I've simplified it a bit, but it should at least point you in the right direction.
 
kiran raja
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I tested the methos posted by "dave taubler" and found that the specialValue mentioned "x", would not serve the purpose. Which means if i have a value x that verfies to true, then the entire table rows will be bolded. Instead only custom renderer could be used to serve the purpose. Suppose based on the column cell value at position 4,we can decide whether the whole row field should be bolded or not. Check out the custom cell renderer below;



Cheers
Kiran
 
kiran raja
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I tested the methos posted by "dave taubler" and found that the specialValue mentioned "x", would not serve the purpose. Which means if i have a value x that verfies to true, then the entire table rows will be bolded. Instead only custom renderer could be used to serve the purpose. Suppose based on the column cell value at position 4,we can decide whether the whole row field should be bolded or not. Check out the custom cell renderer below;



Cheers
Kiran
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ed Nigma hasn't been active for over 4 years. http://faq.javaranch.com/java/DontWakeTheZombies
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!