我只想从边界到边界的JList白色背景。但是,下图显示了我的问题。每个JLists周围都有一个TitledBorder。第二个是原样,白色延伸到边界。第一个我将opaque设置为false,并将背景设置为白色,但只有内部,减去插入是白色。我希望我不必创建ListCellRenderer或覆盖paint方法来完成这么简单的任务。有什么建议吗?
class TextTab extends JPanel
{
String[] textOptions = new String[]{"1 line of text","2 lines of text","3 lines of text","Chest Name","Script with Tail (1 Color)","Script with Tail (2 Color)"};
String[] numberOptions = new String[]{"1\"","2\"","3\"","4\"","6\"","8\"","10\""};
JList<String> textList = new JList<String>(textOptions);
JList<String> numberList = new JList<String>(numberOptions);
GridBagLayout ttGlay = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
JPanel textNumOptions = new JPanel();
JScrollPane textNumOptionsPane = new JScrollPane(textNumOptions);
public TextTab()
{
textList.setBorder(new TitledBorder("Standard Text"));
textList.setOpaque(false);
textList.setBackground(Color.WHITE);
numberList.setBorder(new TitledBorder("Pre-Cut Numbers"));
setLayout(ttGlay);
gbc.weightx = 1;
gbc.weighty = 1;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = gbc.NORTH;
gbc.fill = gbc.BOTH;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.insets = new Insets(10,10,0,0);
add(textList,gbc);
gbc.gridx = 1;
gbc.gridy = 0;
gbc.anchor = gbc.NORTH;
gbc.fill = gbc.BOTH;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.insets = new Insets(10,0,0,10);
add(numberList,gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.anchor = gbc.NORTH;
gbc.fill = gbc.BOTH;
gbc.gridwidth = 2;
gbc.gridheight = 1;
gbc.insets = new Insets(0,10,10,10);
add(textNumOptionsPane,gbc);
}
}