Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7542677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:13:49+00:00 2026-05-30T08:13:49+00:00

I have a JTable with custom TableCellRenderer. public class DateCellRenderer extends DefaultTableCellRenderer { private

  • 0

I have a JTable with custom TableCellRenderer.

public class DateCellRenderer extends DefaultTableCellRenderer {

    private static final long serialVersionUID = 58L;

    public DateCellRenderer() {
        super();
        setHorizontalAlignment(CENTER);     
        setOpaque(true);
    }
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {         
        if (value instanceof Date) {
            String date = new SimpleDateFormat("dd-MM-yyyy").format((Date) value);
            setText(date);
        }
        return this;
    }
}

Also in my application I have a drop down menu by which I can change the look and feel. This drop down menu is in a parent frame and the table is in a dialog. When the dialog is opened the parent frame is inaccessible. So to change the look and feel I have to close the dialog first.

Now in a particular skin if the table is populated by some data and I change the look and feel from parent frame and again open the dialog then the column, where I have added the TableCellRenderer, is keeping the old look and feel. It is not updating while the other columns render themselves in the new look and feel.

I am unable to find the problem and its solution. Any help is appreciable.

Note: The look and feel update of the application is made by the following snippet

javax.swing.UIManager.setLookAndFeel(uiProperties.getThemeModel().getThemeClass());
ComponentFactory.getLibraryFrame().getRootPane().updateUI();
for (int i = 0; i < Frame.getWindows().length; i++) {
    SwingUtilities.updateComponentTreeUI(Frame.getWindows()[i]);
}
for (int i = 0; i < Frame.getFrames().length; i++) {
    SwingUtilities.updateComponentTreeUI(Frame.getFrames()[i]);
}

Thanks in advance.

In HiFi theme chosen first:
enter image description here

Then I change the theme to Fast, and the second column “Released” not updated its ui:
enter image description here

The JTable is:

public class MovieSearchResultTable extends BaseTable {

    private static final long serialVersionUID = 45L;

    public MovieSearchResultTable(TableModel tableModel) {
        super(tableModel);
        LibraryLogger.initMessage(getClass().getSimpleName());
    }

    @Override
    public void initialize() {
        setFillsViewportHeight(true);
        setAutoResizeMode(AUTO_RESIZE_OFF);
        getColumnModel().getColumn(1).setCellRenderer(new DateCellRenderer());//if I comment out this line then no problem. but without CellRenderer how could I format a Date, if I use formatted String instead of Date, then the column will not sort!!
    }

    @Override
    public boolean getScrollableTracksViewportWidth() {
        return getPreferredSize().getWidth() < getParent().getWidth();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:13:51+00:00Added an answer on May 30, 2026 at 8:13 am

    The solution, you need to override public Component prepareRenderer(TableCellRenderer renderer, int row, int column)

    Here is the class:

    public class MovieSearchResultTable extends BaseTable {
    
        private static final long serialVersionUID = 45L;
    
        private int rolloverRowIndex = -1;
    
        public MovieSearchResultTable(TableModel tableModel) {
            super(tableModel);
            LibraryLogger.initMessage(getClass().getSimpleName());
        }   
    
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component component = super.prepareRenderer(renderer, row, column);
            Color foreground = getForeground();
            Color background = getBackground();
            if (isRowSelected(row)) {
                foreground = getSelectionForeground();
                background = getSelectionBackground();
            }
            else if (row == rolloverRowIndex) {
                foreground = getSelectionForeground();
                background = ColorHelper.brighter(getSelectionBackground(), 40);
            }
            else if (row % 2 == 0) {
                background = ColorHelper.brighter(getParent().getBackground(), 20);
            }
            component.setForeground(foreground);
            component.setBackground(background);
            return component;
        }
    
        private class RolloverListener extends MouseInputAdapter {
    
            public void mouseExited(MouseEvent e) {
                rolloverRowIndex = -1;
                repaint();
            }
    
            public void mouseMoved(MouseEvent e) {
                int row = rowAtPoint(e.getPoint());
                if (row != rolloverRowIndex) {
                    rolloverRowIndex = row;
                    repaint();
                }
            }
        }
    
        @Override
        public void initialize() {
            setFillsViewportHeight(true);
            setAutoResizeMode(AUTO_RESIZE_OFF);
            TableColumnModel tableColumnModel = getColumnModel();
            for(ComponentConstant.ColumnName columnName : ComponentConstant.Column.MOVIE_SEARCH_RESULT_TABLE) {
                int order = columnName.getOrder();
                TableColumn tableColumn = tableColumnModel.getColumn(order); 
                if(order == 0) {
                    continue;
                }
    
                tableColumn.setCellRenderer(RendererFactory.getMovieSearchResultTableCellRenderer());
            }
            RolloverListener listener = new RolloverListener();
            addMouseMotionListener(listener);
            addMouseListener(listener);
        }
    
        @Override
        public boolean getScrollableTracksViewportWidth() {
            return getPreferredSize().getWidth() < getParent().getWidth();
        }
    }
    

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a basic custom JTableModel as follows public class CustomTableModel extends DefaultTableModel
I have implemented a custom Table Model as follows: public class MyTableModel extends AbstractTableModel
I have a custom editor composed of several components. Something like: class MyCellEditor extends
I have a custom TableCellRenderer (ValueRenderer) for a JTable, the cell is a Checkbox
I have a JTable with a custom TableCellRenderer and a custom TableCellEditor . By
Alright. I have implemented a custom JTable model that includes the whole @Override public
I have a JTable with a custom TableModel called DataTableModel . I initialized the
I have a JTable inside of a JScrollPane . I am creating a custom
I have a custom cell renderer set in JTable and it works but instead
I have a JTable in Java that has a custom dataMOdel and custom renderer.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.