Multi-colored JTable column heading?  How?

Hi,
I'm looking for a way to have JTable column heading text
that can be displayed in multiple colors, so one string
in one column header, might have each letter a different
color.
My application requires highlighting some of the letters
of a word as red, while others are normal text (black).
I've been using multi-line strings to simulate vertical
naming for my column header, for example:
PPP
I I I
N N N
1 2 3
for PIN1, PIN2, PIN3. The column data has a binary
one or zero for each pin, grouped together in one JTable
column. In my application, if there is an error, I want to
color just the text representing, say PIN2 red and leave
the surrounding PIN1 and PIN3 black.
What approach should I take for doing this with JTable?
Thanks!
John Roberts
[email protected]

You should override the default cell renderer used by Java
- JTable.getTableHeader().setDefaultRenderer(yourRenderer)
Extend yourRenderer from JLabel and use HTML tags to change the color.
- setText on JLabel with the HTML code like "<HTML> <BODY> <FONT COLOR="red"> A </FONT> <FONT COLOR="green"> B </FONT></BODY> </HTML>"

Similar Messages

  • (simple q) how do I change the font in a JTable column header?  thanks

    how do I change the font in a JTable column header?
    thanks

    JTableHeader header = yourTable.getTableHeader();
    // Set to serif, bold, size 12...
    header.setFont( new java.awt.Font( "serif", 1, 12 ) );
    // you can set others like color and border, too.
    header.setBackground(Color.white);
    header.setBorder( new EmptyBorder(15,2,15,2) );

  • How to change JTable column header text

    How do you set the text in the JTable column headers? I know you can create a JTable specifying the text in an array:
    <li>JTable(Object[][] rowData, Object[] columnNames)
    But if you create the JTable specifying a TableModel,
    <li>JTable(TableModel dm)
    the header text defaults to "A", "B", "C", etc. I cannot figure out how to access the text in the header names so it can be changed to something useful. I know how to get the JTableHeader for the table, but it does not seem to have methods for actually setting header values.

    I'm sure that model allows you to specify header values so you don't have to do so manually. I would be very surprised if it didn't override the default getColumnName() method to provide a reasonable names.She wasn't writing the class, but [url http://forums.oracle.com/forums/thread.jspa?messageID=9200751#9200751]outlining a design for me to implement. And, based on a previous comment I had made, I think she assumed I wanted the new design to look as much like the old as possible. There were no headers in the original design, which wasn't even a table.
    Anyway, this works:
        final static String statisticsColumnNames[] = {
         "Type", "Count",
         "Red QE", "Green QE", "Blue QE", "Average QE",
         "Distance"
         qErrors = new QEBeanTableModel();
         JTable errorTable = new JTable(qErrors);
         TableColumnModel tcm = errorTable.getColumnModel();
         for (int col = 0; col < statisticsColumnNames.length; col++)
             tcm.getColumn(col).setHeaderValue(statisticsColumnNames[col]);
    It looks like setHeaderValue() on the TableColumn is what I was looking for.Again, only used if you are dynamically changing the values at run time or you don't like the defaults provided by the Bean-aware model.I coded the above before I read your last post. The QEBeanTableModel is extremely specific to my program. I.e. I cannot imagine it being used anywhere else. Would it still be better to implement a getColumnName() within the table model? Looking at your [url http://www.camick.com/java/source/RowTableModel.java]RowTableModel.java source, I can see that it would not be difficult to do so.
    Just decided to add the getColumnName() method. This whole sub-project is based on implementing a clean modern design (and learning about Java Beans). You've clearly stated twice that the method I have implemented is for dynamic header values only, which has already answered what I asked last paragraph.

  • How to have a combobox in JTable column header?

    Any simple ways for doing this? I am trying to get a filter to a JTable, so that only the rows containing the selected value in that column would be shown.
    I first need to get this combobox into the header of a column.

    Thanks.
    I have already tried with this way, but it was too long and complicated to implement into my file.
    Could someone post the principles here.
    Like this:
    // create my combobox
    JComboBox myBox = new JComboBox();
    myBox.addItem("Cat");
    myBox.addItem("Dog");
    // put the combobox to column header
    ??? ANY CODE HERE ???
    Tnx ahead!
    OK!
    AUlo

  • Background color for column heading

    Hi,
    I have 5 columns in my report and I would like to have different background color for column headings. How can I do this in report templates?
    I was looking at Column heading section-
    <th class="t10ReportHeader"#ALIGNMENT# id="#COLUMN_HEADER_NAME#">#COLUMN_HEADER#</th>
    How can I specify backgrund colors for all columns here?
    Thanks in advance

    G'day Karen,
    Thanks for ur reply.
    I have seen this note before, its not that the header colors have changed after latest SP was applied in our systems. Also the ABAP and JAVA stacks are in sync.
    Scenario is that we are trying to set up a new Portal theme for Enterprise Reporting with some specific color codes (hex codes).
    What i have observed is Characterstics Header background color is set up using the element "Background Color of Level 1 Column Heading ".
    While the Background color for Key Figures header is using element "Background Color of Level 2 Column Heading ".
    But the problem is element "Background Color of Level 2 Column Heading " is also used as the Background color for Standard Characterstics cell, so if we make it same the whole report of the same color, which we dont want.
    Requirement is to get the same Background color for Header cells (both Char. and Key Figure headers).
    Any further suggestions will be appreciated.
    Thanks
    CK

  • JTable column header to span multiple columns

    Hi people. I've spent the last day trying to do this with no luck. Most of the links in the forum are old and don't exist any more and the ones that lead to some code end up not working on java 5 (I can compile and run but the result is not what I wanted)!
    So my question is this, how do I have a column header that spans more than one column, which has individual column headers below it?
    Thanks, Paul.
    EDIT: I should point out that this is the place I've tried and although the screen shot of the first example looks exactly like what I want to do, it does not work as advertised. [http://www.crionics.com/products/opensource/faq/swing_ex/JTableExamples1.html]
    Edited by: Boomah on 05-Nov-2008 15:08

    Something like this?import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.util.Collections;
    import java.util.Enumeration;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.TableColumnModelEvent;
    import javax.swing.event.TableColumnModelListener;
    import javax.swing.table.*;
    public class MultiSpanHeader {
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new MultiSpanHeader().makeUI();
       public void makeUI() {
          final JTable table = new JTable(5, 6);
          final JTableHeader header = table.getTableHeader();
          header.setReorderingAllowed(false);
          final TableColumnModel model = table.getColumnModel();
          Enumeration<TableColumn> enumColumns = model.getColumns();
          final List<TableColumn> columns = Collections.list(enumColumns);
          final JTable dummy = new JTable(0, 3);
          final JTableHeader dummyHeader = dummy.getTableHeader();
          dummyHeader.setReorderingAllowed(false);
          dummyHeader.setResizingAllowed(false);
          final TableColumnModel dummyModel = dummy.getColumnModel();
          Enumeration<TableColumn> enumDummyColumns = dummyModel.getColumns();
          final List<TableColumn> dummyColumns = Collections.list(enumDummyColumns);
          model.addColumnModelListener(new TableColumnModelListener() {
             @Override
             public void columnAdded(TableColumnModelEvent e) {
             @Override
             public void columnRemoved(TableColumnModelEvent e) {
             @Override
             public void columnMoved(TableColumnModelEvent e) {
             @Override
             public void columnMarginChanged(ChangeEvent e) {
                dummyColumns.get(0).setWidth(columns.get(0).getWidth());
                dummyColumns.get(1).setWidth(columns.get(1).getWidth() +
                      columns.get(2).getWidth());
                dummyColumns.get(2).setWidth(columns.get(3).getWidth() +
                      columns.get(4).getWidth() + columns.get(5).getWidth());
             @Override
             public void columnSelectionChanged(ListSelectionEvent e) {
          JScrollPane pane = new JScrollPane(table);
          pane.setPreferredSize(new Dimension(600, 200));
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(pane);
          frame.pack();
          JPanel panel = new JPanel(new GridLayout(2, 1));
          panel.add(dummyHeader);
          panel.add(header);
          pane.getColumnHeader().setView(panel);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
    }Note: this is just presented as an idea, would need a lot of work to make it robust and flexible enough for practical use.
    db

  • Interactive Report, issue with backgroud color of Column Heading.

    Hi,
    I am using Theme -16
    and there is a Interactive Report with the following columns Headings
    Employee Name   Employee No  DOB
    Now, the label of the first column is changed from Employee Name to Employee<br>name.
    The column heading is now displayed as follows.
    Employee   Employee No   DOB
    Name         problem is when I add a break in any of the column heading..the background color of the column headings is different than the first one (little bit darker).
    Why the background ground of the column heading is different in both these cases??.
    Thanks,
    Deepak

    Why the background ground of the column heading is different in both these cases??.The report heading background is controlled by the CSS rule
    .apexir_WORKSHEET_DATA th {
      background: #4e4e4e;
      font-weight: bold;
      color: #fff;
      border-top: 1px #ccc solid;
      border-bottom: 1px #aaa solid;
      white-space: nowrap;
      vertical-align: center;
      letter-spacing: 1;
      font-size: 8pt;
      background-image: url(../ws/report_bg.gif);
      background-repeat: repeat-x;
    }This uses a [gradient image|http://apex.oracle.com/i/ws/report_bg.gif] that is repeated horizontally to provide a shaded background from light to dark grey. As the background image doesn't repeat vertically, when the height of the heading is more than the height of the image the gradient is replaced by the underlying background colour (#4e4e4e). This is what's happening when the break is inserted into the header text: the height of the heading increases, causing more of the darker area of the background image/underlying colour to be visible.

  • JTable Column Header Problem, Please help me

    What Listener I have to used to get the column index when user change the width of column header using mouse.

    There is no listener that reports this activity. The TableColumnModelListener can only tell you if columns change position or are added/removed from the column model.
    To detect changes, you will need to use a brute force mechanism, namely, to extend the JTableHeader class just a bit.
    When the user clicks on a header to resize a column, there is a property in JTableHeader called ResizingColumn that has a type of TableColumn. It is set by the UI delegate when the drag operation starts to the column being resized. When the drag operation ends, the value of ResizingColumn is set to null. You might start with something like this:
      JTable table = new JTable(...);
      MyTableHeader header = new MyTableHeader();
      table.setHeader(header);
      table.setModel(...);
    class MyTableHeader extends JTableHeader
        public void setResizingColumn(TableColumn column)
            super.setResizingColumn(column);
            if (column != null)
                System.out.println("Resizing Column #" + column.getModelIndex());
            else
                System.out.println("Resizing Ended");
    }This will only work for user resizing of columns, not for sizes changed programmatically or by the automatic sizing features of the header.
    Mitch Goldstein
    Author, Hardcore JFC (Cambridge Univ Press)
    [email protected]

  • My ipad has multi-colored lines on it how do i fix it?

    My iPad Mini has mutli-colored lines across it how do i fix it? i tried turning it on n off i restored it but nothing will work

    You can't fix it.  You need to make a reservation at the Genius Bar at the nearest Apple Store.   Use the link below to find one near you.  Before attending the reservation you should create a backup of the device.  You can use iTunes but ICloud should prove more convenient.
    http://www.apple.com/retail/locator/

  • JTable : column header with subheaders

    I need to create a table that looks like this:
    ======================
    Car....|...PRICE......
    .......|dollars.|euros
    ======================
    camry..|18K.....|17k...
    bmw....|80K.....|76K...
    metro..|22K.....|30K...
    (sorry for lousy "graphics")
    My quesion is about the two-layered "PRICE" column header that has two subheaders for two different currencies.
    What is the best way to approach this?

    So there's no standard feature for that (like in HTML)-- you basically have to implement it all yourself?

  • Arrow on JTables column header

    Hey guys,
    I have a few dialogs with tables on etc, everythings fine, its just one table when the program runs, when u hovver(sp?) over the line on the column header it normally turns into a black arrow like so <--> and the you can resize it.
    But this one table wont do that, ive created these in netbeans and just cant see the difference with the other tables. the columns are still resizable just remains an normal arrow though rather than <-->
    Thanks for any help

    You can't resize the column if use the code below,but the arrow will display
    TableColumn tableColumn = this.getTableHeader().getColumnModel().getColumn(i);
                             tableColumn.setPreferredWidth(columnsize);
                             tableColumn.setMinWidth(columnsize);
                             tableColumn.setMaxWidth(columnsize);reply if it help you..

  • How to use JButton as a JTable column header?

    I'd like to use JButtons as my JTable's column headers.
    I built a JButton subclass which implemented TableCellRenderer and passed it to one of my table column's setHeaderRender method. The resulting header is a component that looks like a JButton but when clicked, it does not visually depress or fire any ActionEvents.

    You might want to check this example and use it accordingly for your requirements.
    http://www2.gol.com/users/tame/swing/examples/JTableExamples5.html
    Reason: The reason you're unable to perform actions on JButton is JTableHeader doesn't relay the mouse events to your JButtons.
    I hope this helps.
    have fun, ganesh.

  • JTable column header is not displaying

    Here I have the sample code which is not displaying the header names of each row (Names, Size, Status).
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    public class sample extends JFrame
        JTable table;
        String names[] = {"Names","Size","Status"};
        TableModel model = new AbstractTableModel()
            public Object getValueAt(int row, int col)
                return "Data";
            public int getColumnCount()
                return 3;
            public int getRowCount()
                return 5;
            public String getColumnName(int col)
                return names[col];
        public sample()
            setSize(400,400);
            setDefaultCloseOperation(3);
            Container cp = getContentPane();
            table = new JTable(model);
            cp.add(table);
            setVisible(true);
        public static void main(String a[])
            new sample();
    }Anybody can give idea for me.

    Read the JTable API. It shows you how to do this. In addition it has a link to the tutorial on "How to Use Tables" which contains many examples.

  • JTable column header

    Hello,
    I have the following code:
              JPanel p = new JPanel (new BorderLayout());
              String[] c = {"Other Node", "Direction", "Annotation"};
              Object[][] d = {{"a", "b", "c"}};
              JTable t = new JTable(d, c);
              p.add(t);The problem is that I dont see the column headers (eg "Other node" etc), but I do see the column data, in this case: "a", "b", "c".
    Why I cant see they column headers?
    Thank you,

    See this...
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#simple
    It says if you are not using a scroll pane, you should get the table header using the getTableHeader() and add yourself to the container.
    Hope it helps
    thanks

  • JTable column headings - how to change after instantiation

    Is there a way to change the column headings on a JTable AFTER is has already been instantiated? I reviewed the JTable, TableModel and TableColumn API's in detail. The only method I found related to this is the 'getColumnName' in TableModel. But there is no associated 'setColumnName'.

    Hi!
    You can use the method setHeaderValue(Object) of TableColumn. I wrote a small example:
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableExample {
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            Object[][] data = {
                { "a1", "a2", "a3" },
                { "b1", "b2", "b3" },
                { "c1", "c2", "c3" },
            Object[] headers = {
                "1", "2", "3"
            JTable table = new JTable(data, headers);
            frame.getContentPane().add(new JScrollPane(table));
            frame.pack();
            frame.setVisible(true);
            //  Change header for first column
            TableColumnModel columnModel = table.getColumnModel();
            TableColumn col0 = columnModel.getColumn(0);
            col0.setHeaderValue("New header value");
    }S&oslash;ren

Maybe you are looking for

  • Routing messages in ESB

    Hi.. I am trying to achieve something like this in an ESB project in JDev: I have a routing service which accepts user credentials and then calls a webservice to get the session id. I want to further route the return value of this call to another rou

  • Loosing document from FrameMaker book

    When I import/link a FM book, one document does not get generated as topic. RoboHelp does display the chapter icon under the link in the Project manager, and also indicates the status (green, yellow needs update..) but no topic is present there. Is t

  • PDF zoom in UIWebView

    What a nightmare, I've got over 2 years of cocoa experience but the iPhone SDK is a nightmare. It's easy to come up quick with some results, but than to go all the way is a proper nightmare. It's WEEKS that I stuck with zooming either for PDFs or ima

  • WLPI: managing sub-workflows

    Hi, I read in the documentation that WLPI supports the notion of sub- or child-workflows. I was wondering how this is implemented exactly. Let's say I have one parent workflow consisting of 1 task. This task starts 10 child workflows, each of which w

  • Inactive version to active version

    Hi Gurus. In this scenario I want to convert the PIR's that I am getting from APO in inactive version and I want to convert it into active version before running the MRP.Pls suggest how to do it?