• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable cells and html

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I have a JTable with a unspecified amount of columns and cells.

I want the user to have access to bold, italic , underline and alignment in each and every cell. Is there a way to do it. Please point me in a direction.

If we use html tags in the cell then the users sees the html and we don't want that .

// Mathias
[ December 01, 2005: Message edited by: Mathias Nilsson ]
 
Brian Cole
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mathias Nilsson:
If we use html tags in the cell then the users sees the html


JTable actually does have some limited built-in
html support. For example, if you run this

public static void main(String argv[]) {
TableModel tm = new DefaultTableModel(8, 3);
JTable tab = new JTable(tm);
JFrame f = new JFrame();
f.getContentPane().add(new JScrollPane(tab), BorderLayout.CENTER);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 200);
f.setVisible(true);
}

and type "<html>a <font color=red>b</font> c"
(without the quotes) into a cell and press return,
you will see "a b c" with the 'b' colored red.

This only works if the first six chars are
"<html>" (again without the quotes). There
are other limitations too, but you may want
to play with it.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

I was thining... can I use JLabel in cells and use bold on the fin and alignment on the JLabel?

Does anyone know how to do this?

// Mathias
 
Brian Cole
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mathias Nilsson:
can I use JLabel in cells and use bold on the fin and alignment on the JLabel?


If you take a look at the DefaultTableCellRenderer
class, you'll see that it is a JLabel. So if
you set one as a renderer, you can set its font and
alignment just like you would any other JLabel. You
don't use cell renderers like you use labels, though.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

How do I use the JLabel to paint bold , Italic? I can only do JLabel.getText()..... Otherwise it just prints javax.swing.Jlabel .... and a lot of data in the cell.

// MAthias
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic