嗯,我有相反的问题,检查一下,真的没有人可以没有代码示例,也许有人可以使用TableCellRenderer使用未选择的AlternateTableColor
Nimbus默认值
import javax.swing.*; import javax.swing.table.*; import java.util.Date; import java.util.Vector; import java.awt.*; import java.awt.event.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import javax.swing.UIManager.LookAndFeelInfo; public class TableTestPanel extends JPanel { private static final String[] COLUMN_NAMES = {"List ID", "Expiration Date", "Status", "Date Created"}; private static final DateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy"); private static final long serialVersionUID = 1L; private static class StatusPanel extends JPanel { private static final long serialVersionUID = 1L; private JRadioButton theSingleOption; private JRadioButton theMarriedOption; private JRadioButton theDivorcedOption; StatusPanel() { super(new GridLayout(3, 1)); setOpaque(true); ButtonGroup buttonGroup = new ButtonGroup(); theSingleOption = new JRadioButton("Single"); theSingleOption.setOpaque(false); add(theSingleOption); buttonGroup.add(theSingleOption); theMarriedOption = new JRadioButton("Married"); theMarriedOption.setOpaque(false); add(theMarriedOption); buttonGroup.add(theMarriedOption); theDivorcedOption = new JRadioButton("Divorced"); theDivorcedOption.setOpaque(false); add(theDivorcedOption); buttonGroup.add(theDivorcedOption); } public Status getStatus() { if (theMarriedOption.isSelected()) { return Status.MARRIED; } else if (theDivorcedOption.isSelected()) { return Status.DIVORCED; } else { return Status.SINGLE; } } public void setStatus(Status status) { if (status == Status.MARRIED) { theMarriedOption.setSelected(true); } else if (status == Status.DIVORCED) { theDivorcedOption.setSelected(true); } else { theSingleOption.setSelected(true); } } } private static class Status { static final Status SINGLE = new Status("Single"); static final Status MARRIED = new Status("Married"); static final Status DIVORCED = new Status("Divorced"); private final String myName; // for debug only private Status(String name) { myName = name; } @Override public String toString() { return myName; } } private static class TableEntry { private static int instanceNumber; private Long theId; private Date theExpirationDate; private Status theStatus; private Date theCreationDate; TableEntry() { instanceNumber++; theId = new Long(instanceNumber); theExpirationDate = new Date(); theStatus = Status.SINGLE; theCreationDate = new Date(); } TableEntry(Long anId, Date anExpirationDate, Status aStatus, Date aCreationDate) { theId = anId; theExpirationDate = anExpirationDate; theStatus = aStatus; theCreationDate = aCreationDate; } public Long getId() { return theId; } public Date getExpirationDate() { return theExpirationDate; } public Status getStatus() { return theStatus; } public Date getCreationDate() { return theCreationDate; } public void setId(Long anId) { theId = anId; } public void setExpirationDate(Date anExpirationDate) { theExpirationDate = anExpirationDate; } public void setStatus(Status aStatus) { theStatus = aStatus; } public void setCreationDate(Date aCreationDate) { theCreationDate = aCreationDate; } } private static class MyTableModel extends AbstractTableModel { private static final long serialVersionUID = 1L; private Vector