-1

When using HTML in my JTable cells it will be displayed as

  <html><b>Example</html></b>

and not with the proper html styles. I read that default renderers work with html text. How do i change my custom renderer to display HTML correctly ?

My Jtable:

tab_months = new JTable(tabmod_months) {        
    @Override public Component prepareRenderer(TableCellRenderer renderer,
            int row,
            int col){
        Component c = super.prepareRenderer(renderer, row, col);
        int selCol = tab_months.getSelectedColumn();
        int selRow = tab_months.getSelectedRow();
        if ( selCol != -1 && selRow != -1 ){
            if (row == selRow){
                c.setBackground(new Color(163,198,255));
            } else {
                c.setBackground(new Color(255,240,245));    
            }               
        }

        if (row>=0 && row<listOpenmonths.size()+1) {
            setToolTipText(listOpenmonths.get(row).getmonthsString());
        }   

        return c;
    }
};
K. Wenzel
  • 13
  • 1
  • 7
  • HTML has only the basic support in Swing (ok, the tags like , , spans, divs, and tables are supported, but no css features). So you cannot use the most of style features. But you can write your own renderer, when you extend JPanel and implement `TableCellRenderer` interface. In this case you can style your data using Swing layout possibilities. – Sergiy Medvynskyy Aug 25 '18 at 17:34
  • 1
    `How do i change my custom renderer to display HTML correctly ?` - you don't do anything. The default renderer for the JTable is a JLabel. A JLabel knows how to display basic HTML. Using the bold tag works fine for me. Post your [mcve] that demonstrates the problem. So start by create a JFrame with a standard JTable and add your HTML string to the TableModel. Get that working. Then try customizing the classes with your custom code. If it stops working you know what you changed and where the problem is. Then you have more information that you can include in your question. – camickr Aug 25 '18 at 20:13
  • @SergiyMedvynskyy *"but no css features"* The Swing HTML rendering engine only supports a limited amount of CSS, but it does support ***some.*** – Andrew Thompson Aug 26 '18 at 00:42

1 Answers1

0

Found the problem: my html tag was inside of the string and it wasn't recognized...changed the string format and it worked. Thank you !

K. Wenzel
  • 13
  • 1
  • 7