当在JTable(Nimbus L& F)中编辑数据时,当用户从一个单元格切换到另一个单元格时,不清楚哪个单元格具有焦点.如何更清楚地说明哪个细胞有焦点?我知道有很多属性可以设置来修改Nimbus – 有谁知道我想要哪个属性?
UIManager.put("Table.showGrid",true);
最佳答案
>你看看Renderer concept,
>默认工作于Nimbus Look and Feel,
>某些问题可能与JButtons components (JCheckBox e.i.)有关,但在此论坛上有几次得到解答或解决
原文链接:https://www.f2er.com/java/438122.html>默认工作于Nimbus Look and Feel,
>某些问题可能与JButtons components (JCheckBox e.i.)有关,但在此论坛上有几次得到解答或解决
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RowSorter.SortKey;
import javax.swing.SortOrder;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
public class ImageChangeDemo extends JFrame {
private static final long serialVersionUID = 1L;
private JTable table = new javax.swing.JTable();
private JTable table1 = new javax.swing.JTable();
private static Icon ascendingSortIcon;
private static Icon descendingSortIcon;
public static void main(String args[]) {
//comment out the code below to try in Metal L&F
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
ascendingSortIcon = UIManager.getLookAndFeelDefaults().getIcon("Table.ascendingSortIcon");
descendingSortIcon = UIManager.getLookAndFeelDefaults().getIcon("Table.descendingSortIcon");
//UIManager.getLookAndFeelDefaults().put("Table.ascendingSortIcon",new BevelArrowIcon(BevelArrowIcon.UP,false,false));
//UIManager.getLookAndFeelDefaults().put("Table.descendingSortIcon",new BevelArrowIcon(BevelArrowIcon.DOWN,false));
break;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ImageChangeDemo().setVisible(true);
}
});
}
public ImageChangeDemo() {
setDefaultCloSEOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
JScrollPane pane = new javax.swing.JScrollPane();
//table.setAutoCreateRowSorter(true);
table.setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{"a","q","h","v"},{"b","m","l","h"},{"d","c","a","d"},{"j","o","y","e"}
},new String[]{
"Col 1","Col 2","Col 3","Col 4"
}) {
private static final long serialVersionUID = 1L;
Class[] types = new Class[]{
String.class,String.class,String.class
};
@Override
public Class getColumnClass(int columnIndex) {
return types[columnIndex];
}
});
TableRowSorter