2
我可以知道我知道我可以觸發系統重新繪製JList中的第n行嗎?目前,我做的是觸發器重新繪製JList中的第n行
jList0.repaint(); // Repaint entire JList, which is not efficient.
我只想更新JList中的第n行。
請注意,我想這樣做的原因是我安裝了自定義列表單元格渲染器。列表的GUI外觀將取決於我的應用程序的外部模型階段。
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;
}
};
}