JTable highlights in 1.3.1

Is there a possibility to highlight the vertical and the horizontal highlights together in JTable with version 1.3.1.
I tried table.getColumnsSelectionAllowed() and table.getRowSelectionAllowed() together, and it doesn't work anymore the way it worked in 1.2.1-1.2.2.
Did someone occerded the problem and solved it anyhow?
regards Amnon

hi,
I read the statement " ... you do not want to have the row and the column of the cell selected here but you want to have them highlithed???" this is exactly what i want... to programatically set the focus on a particular row so that it has the blue border, but it is not selected until i explicitly do setSelected(true).... any ideas????
shefali.

Similar Messages

  • JTable: Highlighting multiple rows

    Hello,
    I have a simple problem: I want to highlight rows 2,4 and 8 of a JTable using the colors blue, red and green respectively. (JTable is being used as a spreadsheet)
    How do I do this? Can someone please help.
    Thanks,
    Nadeem

    Search the forum for jtable row +highlight and you should find your answer somewhere on the list:
    http://onesearch.sun.com/search/developers/index.jsp?col=devforums&qp_name=Swing&qp=forum%3A57&qt=%2Bjtable+%2Brow+%2Bhighlight
    ;o)
    V.V.

  • JTable selected cell highlight

    Hi,
    I want to reproduce Excel behaviour in a JTable :
    highlight the cell on which user has clicked once
    show the caret when the user has double-cliked on it.
    The second behaviour looks like being built-in the JTable
    But when the user clicks once on the cell not visual effect appears
    to reflect the click event.
    I would like to have the selected cell "border" painted in another color.
    Would you have a hint for that ?
    thanks

    Thanks you the hint Razor_Blade.
    could you elaborate a bit more please.
    I don't feel like getting deep into rendering stuff now,
    and was expecting a simple solution.
    But if there's no, don't bother.
    It will take the time that it needs but I'll find out.
    thx.

  • JTable cell focus outline with row highlight

    With a JTable, when I click on a row, the row is highlighted and the cell clicked has a subtle outline showing which cell was clicked.
    I would like to do that programatically. I can highlight the row, but I have not been able to get the subtle outline on the cell. My purpose is to point the user to the row and cell where a search found a match. I do not have cell selection enabled, because I want the whole row highlighted.
    My basic code is:
    table.changeSelection(irow, icol, false, false);
    table.scrollRectToVisible(table.getCellRect(irow, icol, true));I keep thinking I just need to find a way to "set focus" to the cell so the subtle outline is displayed, but I cannot find something like that.
    Does anyone have some ideas on how to activate that automatic outline on the cell? I prefer not to write custom cell renderers for this if possible.

    That seems unnecessarily complicated, the outline is the focused cell highlight border so requesting focus on the table should be enough.
    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    public class TestTableFocus {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    final JTable table = new JTable(10, 10);
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.getContentPane().add(new JScrollPane(table));
                    frame.getContentPane().add(new JButton(
                      new AbstractAction("Focus cell") {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            table.changeSelection(5, 5, false, false);
                            centerCell(table, 5, 5);
                            table.requestFocusInWindow();
                        private void centerCell(JTable table, int x, int y) {
                            Rectangle visible = table.getVisibleRect();
                            Rectangle cell = table.getCellRect(x, y, true);
                            cell.grow((visible.width - cell.width) / 2,
                                    (visible.height - cell.height) / 2);
                            table.scrollRectToVisible(cell);
                    }), BorderLayout.PAGE_END);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
    }

  • Highlight JTable Row with Right-Click

    How can I get a JTable to highlight a row when that row is right-clicked? Thanks, Jeremy

    table.addMouseListener(new MouseAdapter()
    public void mouseClicked (MouseEvent e)
    if(e.isMetaDown())
    int row = table.rowAtPoint(e.getX((), e.getY();
    table.setSelectionInterval(row, row);
    });Or something like that.

  • Strange JTable behaviour - everything is highlighted

    Hello all,
    im experiencing some strange JTable behaviour, and im not so sure why. When i run my program, the JTable appears, but all the cells are highlighted in advance. Also, i can now only select one cell at a time. I have set myTable.setSelectionModeListSelectionModel.SINGLE_INTERVAL_SELECTION);  myTable.setCellSelectionEnabled(true);and my renderer code is below. I call the renderer by using the setDefaultRenderer method with(Object.class,myRenderer).
    I have also changed isCellEditable to return true. If i dont use Object.class, and try to use my own custom class, the JTable is not all highlighted, but it doesnt seem to use myRenderer, and when i click on the header of Column A, all cells from column B and beyond become highlight, which is not normal behaviour. I thought the colum you selected should be highlighted.
    Sorry for the long post, i hope the above makes sense...this is really quite bizzare, and im not so sure why this is happening. Thanks for any advice you can give, regards, Rupz
    import javax.swing.*;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.border.*;
    import java.awt.Component;
    import java.awt.Color;
    import java.awt.Rectangle;
    import java.util.*;
    import java.awt.*;
    public class MyTableCellRenderer extends DefaultTableCellRenderer{
         private Font cellFont;
         private LineBorder  selectBorder;
        private EmptyBorder emptyBorder;
         public MyTableCellRenderer() {
              super();
              setOpaque(true);
              emptyBorder  = new EmptyBorder(1, 2, 1, 2);
              cellFont = new Font("Times", Font.PLAIN, 10);
              setFont(cellFont);
              selectBorder = new LineBorder(Color.red);
         private boolean isHeaderCell(int row, int column){return column == 0;}
         public Component getTableCellRendererComponent (JTable myTable, Object value, boolean isSelected, boolean hasFocus, int row, int column){
              //super.getTableCellRendererComponent(myTable, value, isSelected, hasFocus,row, column);
              if (isSelected){
                   super.setForeground(myTable.getSelectionForeground());
                   super.setBackground(myTable.getSelectionBackground());
                   setBorder(selectBorder);
              else{
                   super.setForeground(myTable.getSelectionForeground());
                   super.setBackground(myTable.getSelectionBackground());
                   setBorder(emptyBorder);
         if (hasFocus) {
              setBorder(selectBorder);
              if (myTable.isCellEditable(row,column)) {
                   super.setForeground(UIManager.getColor("Table.focusCellForeground"));
                   super.setBackground(UIManager.getColor("Table.focusCellBackground"));
         else {setBorder(noFocusBorder);}
         setValue(value, isSelected, hasFocus, row, column);
    //      Color bDis = getBackground();
    //      boolean colourEquals = (bDis != null) && (bDis.equals(myTable.getBackground()) ) & myTable.isOpaque();
    //      setOpaque (!colourEquals);
         return this;
         public void setValue (Object value, boolean hasFocus, boolean isSelected, int row, int column){
              if (value instanceof myCell){
                   myCell foo = (myCell)value;
                   Object data = foo.getValue(row,column);
                   if (isHeaderCell(row, column)) {
                    //label cells are center aligned
                        setHorizontalAlignment(JTextField.CENTER);
                       }else {
                              if (data instanceof Number) {
                                  //numbers are right justified
                            setHorizontalAlignment(JTextField.RIGHT);
                              }else {
                                  //everything else is left justified
                            setHorizontalAlignment(JTextField.LEFT);
                          //value to display in table
                       setText((data == null) ? "" : data.toString());
               else {
                          //not cell object so render with toString of that object
                          setText((value == null) ? "" : value.toString());

    Hi VV!
    thanks for the reply - now the table isnt all highlight when loaded, but as for cell celection..thats a different matter. I did have myTable.setCellSelectionEnabled(true); but no, the cell behaviour is really, eally weird, quite hard to explain, but here goes.
    If i try to select cell D1 and D2 - D1 is selected, D2, E2,F2 and so on become selected. If i try to add D3 to the mix, the entire row 3 is selected, and as soon as i let go of the mouse button, the entire table except row 1 gets selected. really really weird. Below is my tableModel and what i do to the table. Thanks for your help,
    regards
    Rupz
    myTable.setModel(new myTableModel(this,40,40));
         // Create a row-header to display row numbers.
         // This row-header is made of labels whose Borders,
         // Foregrounds, Backgrounds, and Fonts must be
         // the one used for the table column headers.
         // Also ensure that the row-header labels and the table
         // rows have the same height.
         numRows = myTable.getColumnCount();
         numCols = myTable.getRowCount();
         TableColumn       aColumn   = myTable.getColumnModel().getColumn(0);
         TableCellRenderer aRenderer = myTable.getTableHeader().getDefaultRenderer();
         Component aComponent = aRenderer.getTableCellRendererComponent(myTable, aColumn.getHeaderValue(), false, false, -1, 0);
         Font  aFont       = aComponent.getFont();
         Color aBackground = aComponent.getBackground();
         Color aForeground = aComponent.getForeground();
         Border      border  = (Border)UIManager.getDefaults().get("TableHeader.cellBorder");
         FontMetrics metrics = getFontMetrics(cellFont);
          * Creating a panel to be used as the row header.
          * Since I'm not using any LayoutManager,
          * a call to setPreferredSize().
         JPanel pnl = new JPanel((LayoutManager)null);
         Dimension dim = new Dimension( 40,  rowHeight*numRows);
         pnl.setPreferredSize(dim);
         // Adding the row header labels
         dim.height = rowHeight;
         for (int ii=0; ii<numRows; ii++) {
           JLabel lbl = new JLabel(Integer.toString(ii+1), SwingConstants.CENTER);
           lbl.setFont(aFont);
           lbl.setBackground(aBackground);
           lbl.setForeground(aForeground);
           lbl.setBorder(border);
           lbl.setBounds(0, ii*dim.height, dim.width, dim.height);
           pnl.add(lbl);
         JViewport vp = new JViewport();
         dim.height = rowHeight*numRows;
         vp.setViewSize(dim);
         vp.setView(pnl);
         // Set resize policy and make sure
         // the table's size is tailored
         // as soon as it gets drawn.
         myTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
         Dimension dimScpViewport = myTable.getPreferredScrollableViewportSize();
         if (numRows>30) dimScpViewport.height = 30*rowHeight;
         else           dimScpViewport.height  = numRows*rowHeight;
         if (numCols>15)
           dimScpViewport.width = 15*myTable.getColumnModel().getTotalColumnWidth()/numCols;
         else
           dimScpViewport.width = myTable.getColumnModel().getTotalColumnWidth();
         myTable.setPreferredScrollableViewportSize(dimScpViewport);
         myTable.repaint();
    And the table model
    public class myTableModel extends DefaultTableModel {
         private MySpread mySpreadsheet;
         public myTableModel (MySpread aSpreadsheet){
              super();
              mySpreadsheet = aSpreadsheet;
         public myTableModel (MySpread aSpreadsheet, int rows,int cols){
              super(rows,cols);
    //                 for(int x = 0; x < rows; x++) {
    //                      myCell temp = new myCell(new Integer(x+1));
    //                  super.setValueAt(temp, x, 0);
            for(int x =0 ; x < rows; x++)
             for (int y = 0; y < cols; y++)
              // we initialize it here
              super.setValueAt(new myCell(rows,cols,("")),x,y);
         mySpreadsheet = aSpreadsheet;
         public boolean isCellEditable(int row, int column) {return true;}  
         

  • JTable cell + isSelected, hasFocus, highlighted ??

    hi
    My JTable has row and column selection disabled, when a cell is clicked, only the outline is highlighted
    It seems that when i click a cell in my JTable that said cell is given focus (has its edge highlighted), and when this cell is clicked the second time it is 'selected'. However there is nothing to indicate to the user that the cell is selected, ie its state is still a single line highlighted border. A double click puts the cell in edit mode.
    My questions are so:
    What state is a cell in when it is internally highlighted with color ?
    Why make the distinction (between focus and selection) if its only possible to get selectedRow() and not getRowWithFocus() ?
    How can i have it so that a sinlge click makes a cell both selected and with focus, i know its down to changing the cell renderer, i tried 'if (hasFocus) { isSelected = true; } but that wasn't working.
    Why does clearSelection not clear the cells which are internally highlighted with color ? And how can i clear those cells ?
    Hope someone can help
    Thanks

    However there is nothing to indicate to the user that the cell is selected, ie its state is still a single line highlighted border.
    Why make the distinction (between focus and selection) if its only possible to get selectedRow() and not getRowWithFocus() ?Normally a table operates in row selection mode and all cells in the selected row are highlighted except the cell that has focus, which uses the single line highlighted border.
    So, in a table that uses single cell selection there are no other selected cells so you only see the focused cell with the highlighted border. If you want to highlight the focused cell you could try overriding the following method of JTable:
    public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
         Component c = super.prepareRenderer(renderer, row, column);
         if (isCellSelected(row, column))
              c.setBackground( getSelectionBackground());
         return c;
    }

  • Sorting highlighted rows in JTable

    I have a sortable JTable. If a user selects a row (highlights it) and then sorts the table the wrong row is selected. After the sort the data in the row that was hightlighted is not the correct data. Basically the hightlighted selection does not follow the data to its new position. Is there a way to keep tract of the internal row indexs so that I can keep the correct rows highlited? Any ideas will be of much help.

    I don't know if this is correct but if you are using TableSorter
    Then you might need to access the int[] indices array that the Sorter uses to tell you where the row you had selected had moved to. To get all the rows that you had selected using
    JTable a = new JTable();
    a.getSelectedRows();...
    I hope this helps...

  • How to highlight the row from the JTable then remove

    hi !!
    i'm using an abstract model in making a table....
    and having a button up and down and delete also!!
    how can i highlight the row when i click down and up!!!
    and when selected or highlighted i can press the button delete ...
    then the data is removed!!!
    pls... i need it!!
    tnx...

    Table row selection should take care of it. By default table rows can be selected.
    The getSelectionModel() method on the JTable gives you access to the row selection model. You can set that either to allow one at a time or multiple selection, and when your delete button is pressed, you access that selection model to decide which rows to delete.
    Add a ListSelectionListener so you can enable or disable your delete button as rows are selected or deselected. JTable will take care of the highlighting.

  • JTable: Allowing the highlight of a row with a right click

    Hi, this is my first post here. I'm using a JTable to display data from a JDBC ResultSet and I added a popup menu to the JTable (activated with the PopupTrigger) to display options related to the selected row like DELETE, UPDATE, etc.
    But the problem is that if you right click (the PopupTrigger that MS Windows has) anywhere on the table the Pop Up shows even if you aren't right clicking over the selected row.
    What I want to do is to:
    * When I right click over a row on the JTable I want to highlight that row and then show the PopUp menu so it correctle performs the operation on the row the Menu is placed over.
    * Or another option is not to show the PopUp at all in case the cursor is not over the selected row.
    Anyway, the bottom line is that I need a way to know in which row of the JTable is the mouse over?
    Thanks in advance.

    Thanks my man! That was my missing piece!
    I also used the JTable.addRowSelectionInterval(clickedRow, clickedRow) to highlight the clicked row.
    10 Duke Dollars coming your way.
    class IFramePersons_jTablePerson_mouseAdapter
            extends java.awt.event.MouseAdapter
        IFramePersons adaptee;
        IFramePersons_jTablePerson_mouseAdapter(IFramePersons adaptee)
            this.adaptee = adaptee;
        public void mouseClicked(MouseEvent e)
            if(e.getClickCount() == 2)
                adaptee.jTablePerson_mouseClicked(e);
        public void mousePressed(MouseEvent e)
            maybeShowPopup(e);
        public void mouseReleased(MouseEvent e)
            maybeShowPopup(e);
        private void maybeShowPopup(MouseEvent e)
            if(e.isPopupTrigger())
                int clickedRow = adaptee.jTablePerson.rowAtPoint(e.getPoint());
                adaptee.jTablePerson.addRowSelectionInterval(clickedRow, clickedRow);
                adaptee.jPopupMenuRow.show(e.getComponent(), e.getX(), e.getY());
    }

  • Highlight JTable Header

    Hello,
    I want to be able to change the color of a JTable header of a column ie highlight it when a user clicks on the table header. Is there a way to do this? I'vd done a google search but nothing seems to address this. Any help is much appreciated. Thanks.
    vyang

    Try this piece of code on for size. The HeaderRenderer class is far from complete but it should give you something substancial to work with. This renderer also using GradientPainting to give you an extra boost in terms of appearance.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.datatransfer.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.filechooser.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    public class HeaderRenderer extends DefaultTableCellRenderer implements
                    MouseListener, MouseMotionListener {
        Color bg = new Color(242,242,255), fg = Color.black;
        Rectangle paintingRect = null,
            lpr = null; //last painted rect
        JTableHeader header = null;
        public boolean isOnCol = false, highlightClickedCol = false;
        private int paintingCol = -1, clickedCol = -1, currentCol = -1;
         * Buffer gradient paint.
        GradientPaint gp = null, hoverGradient, columnGradient;
         * The current sorting state of the columns
        SortOrder sortOrder = null;
        public HeaderRenderer() {
            super();
            setFont( getFont().deriveFont(Font.BOLD) );
            //setBackground( bg );
            setForeground( fg );
            setOpaque(false);
            setBorder( BorderFactory.createCompoundBorder (BorderFactory.createMatteBorder(0,0,1,1, new Color(200,200,230) ),
                            BorderFactory.createEmptyBorder(4,7,4,4)) );
            setHighlightClickedColumn(true);
        public void setColumnGradient(GradientPaint gp) {
            this.columnGradient = gp;
        public void setHoverGradient(GradientPaint gp) {
            this.hoverGradient = gp;
        public GradientPaint getColumnGradient() {
            return columnGradient;
        public GradientPaint getHoverGradient() {
            return hoverGradient;
        public void setHighlightClickedColumn(boolean b) {
            highlightClickedCol = b;
        public void paintComponent(Graphics g) {
            Rectangle rect = paintingRect;
            Graphics2D g2 = (Graphics2D)g;
                g2.setPaint(gp);
                g2.fillRect( 0, 0, rect.width, rect.height );
            FontMetrics fm = g.getFontMetrics();
            int strWidth = fm.stringWidth( getText() );
            /*if(currentCol == clickedCol) {
                if( sortOrder == SortOrder.ASCENDING )
                    new ArrowIcon( ArrowIcon.UP ).paintIcon(this, g, strWidth + 15, 8);
                else if(sortOrder == SortOrder.DESCENDING )
                    new ArrowIcon( ArrowIcon.DOWN ).paintIcon(this, g, strWidth + 15, 8);
            sortOrder = null;
            super.paintComponent(g);
        public void attachListener() {
            header.addMouseListener(this);
            header.addMouseMotionListener(this);
        public void mouseEntered(MouseEvent e) {
            isOnCol = true;
        public void mouseExited(MouseEvent e) {
            isOnCol = false;
            paintingCol = -1;
            header.repaint();
        public void mouseReleased(MouseEvent e) {}
        public void mouseClicked(MouseEvent e) {
            clickedCol = header.columnAtPoint( e.getPoint() );
        public void mousePressed(MouseEvent e) {}
        public void mouseMoved(MouseEvent e) {
           // isOnRow = true;
            paintingCol = header.columnAtPoint( e.getPoint() );
            paintingRect = header.getHeaderRect( paintingCol );
            header.repaint( paintingRect.x, paintingRect.y, paintingRect.width, paintingRect.height );
            if(lpr != null) {
                header.repaint(lpr.x, lpr.y, lpr.width, lpr.height);
            lpr = paintingRect;
        public void mouseDragged(MouseEvent e) {
            //isOnRow = true;
            paintingCol = header.columnAtPoint( e.getPoint() );
            paintingRect = header.getHeaderRect( paintingCol );
            header.repaint( paintingRect.x, paintingRect.y, paintingRect.width, paintingRect.height );
            if(lpr != null) {
                header.repaint(lpr.x, lpr.y, lpr.width, lpr.height);
            lpr = paintingRect;
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
             boolean hasFocus, int row, int col) {
            currentCol = col;
            if(header == null) {
                header = table.getTableHeader();
                attachListener();
            if(table.getRowSorter() != null && table.getRowSorter().getSortKeys().size() > 0 ) {
                java.util.List<? extends RowSorter.SortKey> keys = table.getRowSorter().getSortKeys();
                for(RowSorter.SortKey key: keys) {
                    if(key.getColumn() == col) {
                        sortOrder = key.getSortOrder();
            Rectangle rect = table.getTableHeader().getHeaderRect(col);
            if( (isOnCol && paintingCol == col) || (clickedCol == col && highlightClickedCol)  ) {
                gp = new GradientPaint( rect.x, rect.y + rect.height, new Color(200,220,235),
                                    rect.x, rect.y, new Color(230,235,250)  );
                setForeground( new Color(50,50,50) );
            } else {
                gp = new GradientPaint( rect.x, rect.y + rect.height, new Color(235,240,245) ,
                                        rect.x, rect.y, new Color(245,250,255) );
                setForeground( new Color(100,120,160) );
            paintingRect = rect;
            //JLabel renderer = new JLabel();
            setText( value == null ? "" : value.toString() );
            //setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
            //   brdr) );
            return this;
        public static void main(String[] args) {
            DefaultTableModel model = new DefaultTableModel(20,5);
            JTable table = new JTable( model );
                table.getTableHeader().setDefaultRenderer( new HeaderRenderer() );
            JFrame frame = new JFrame("Header Renderer Test");
                frame.add( new JScrollPane(table) );
                frame.pack();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
    }ICE

  • How to automatically highlight / bold words in a JTable cell?

    how do i do it?
    i have an Object called Data (where toString() is the same as getDataName()).
    and i want the JTable to either highlight or bold specific words (using the bold HTML tags) that are present in a SortedSet.
    i do not want the dataName to be changed by directly manipulating the Object because the Data Objects were taken from the DB and i need the Objects and the records to be synchronised, and because the words in the SortedSet itself are subject to changes (add/edit/remove).
    thanks.

    Edit: removed
    db
    Cross posted
    http://www.java-forums.org/awt-swing/47138-how-automatically-highlight-bold-words-jtable-cell.html
    Edited by: Darryl Burke

  • Highlighting different rows within a JTable

    I have a JTable that has 20 rows. I also have a Jlist next to the JTable. When someone selects something within the Jlist I want to highlight certain rows depending on what was selected within that list. For instance if a user selects Item1 within the list I want to highlight the 3rd, 8th and 11th row within a JTable. The problem is the JTable API will let you highlight a number of rows but not allow you to specify single rows to highlight at one time. When I run my code to do this I get the last row highlighted. The reason is because the 3rd and 8th row do get highlighted but when I call the setRowSelectionInterval(i, i); where i is the row to highlight it has already passed and will end up highlighting the 11th row only. Is there any work around for this?

    First, make sure you table supports multi-select. Turn it on in this case, otherwise you can't select multiple items.
    To color different rows, you'll have to set a cell renderer and use it to color those rows. It's possible to collor each and every cell a different color, set fonts, images, etc..you just need a good cell renderer.

  • 2 Related JTables and highlighting

    Hi,
    I currently have a form with 2 JTables. They are related, and work where data is moved from 1 table to the other.
    I have used the prepareRenderer to display the duplicate rows in a different colour, and that is all working great. However now I am trying to make it so that when I click on one of the duplicate rows, it will highlight the corresponding row in the other table in a different colour and hopefully also centre it in that tables view.
    So far, I have had no luck in doing this .... or finding any references.
    If anyone is able to give me a nudge in the right direction, that will be very appreciated.
    Thanks
    Matt

    JTable table = new JTable(data, column);
    JScrollPane scrollPane = new JScrollPane(table);
    JTable tableTwo = new JTable(data, column);
    JPanel panel = new Panel(new GridLayout(0,1));
    panel.add(scrollPane);
    panel.add(tableTwo);
    That is basically how my code looks like. I think i need to dynamically set the size of the table at runtime,
    but it may be the panel. I can adjust to any type of format, as long as 2 tables look like one and are on
    top of each other. table one's row size is dynamic and table two's row size is always 1.

  • JTable, how to highlight cells with tooltips?

    Hello all!
    Mine problem is descriped in the topic - I though about custom cell renderer but I dont have an Idea how to change background for many other cells in other rows and don't change background in whole columns. Any of You could help?

    Hey thanks for replying.
    With code like that:
    public class yellowCellRenderer
      extends DefaultTableCellRenderer
      private int whichRow = 0;
      public yellowCellRenderer(int saveToRow)
        this.whichRow = saveToRow;
      public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column)
        if(this.whichRow == row){
         this.setBackground(Color.YELLOW);  // All columns verified were empty - set our background RED
        return this;
    }and usage:
         comments.add(comment);
         JTable table = getMainTable();
         TableColumnModel colModel = table.getColumnModel();
         for(int i=0;i<comment.length;i++){
             if(!Main.isStringEmpty((String)comment)){
              TableColumn column = colModel.getColumn(i);
              column.setCellRenderer(
                   new yellowCellRenderer(table.getRowCount()-1)
    Every each cell in column gets yellow background... What am I doing wrong?

Maybe you are looking for