tags:

views:

37

answers:

1

May I know know I can trigger system to repaint nth row in JList? Currently, what I did is

jList0.repaint();    // Repaint entire JList, which is not efficient.

I am only interested to update nth row in JList.

Please note that the reason I want to do so, is that I install a custom list cell renderer. The GUI look of the list, will depending on the external model stage of my application.

public ListCellRenderer getListCellRenderer() {
    return new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (component != null && value != null) {
                final MainFrame mainFrame = MainFrame.getInstance();
                final String portfolioName = mainFrame.getJStockOptions().getPortfolioName();

                if (value.toString().equals(portfolioName)) {
                    component.setFont(new Font(component.getFont().getName(), Font.BOLD, component.getFont().getSize()));
                }
            }
            return component;
        }
    };
}
A: 
list.repaint( list.getCellBounds(...) );
camickr