Trigger for redrawing the nth line in the JList
May I know, know that I can start the system to redraw the nth line in the JList? Currently I have done
jList0.repaint(); // Repaint entire JList, which is not efficient.
I'm only interested in updating the nth line in the JList.
Note that the reason I want to do this is because I am setting up a custom list renderer. The look of the list GUI will depend on the external model phase 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;
}
};
}
+2
source to share