我有一个jscrollpane动态创建jtable。我正在尝试解决边界问题。如果我指定一个边框,我会在没有表格数据的区域附近找到边框。如果我在滚动窗格中创建空边框,我会得到所需的边框,但标题周围的边框不存在。我将包括两个图片,以便您可以看到问题。Swing - JTable JScrollPane删除下边框或添加标题边框
左边框和底边框不应该在那里。
我将包含相关的代码。
一类
private void createPanels(JButton close, JButton mapButton){
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
add(mainPanel);
setModal(true);
JPanel topPanel = new JPanel(new BorderLayout(0, 0));
topPanel.setPreferredSize(new Dimension(400, 30));
JLabel title = new JLabel("Mapping Flags");
title.setFont(new Font("SansSerif", Font.PLAIN, 17));
JPanel panelForTitle = new JPanel(new FlowLayout(FlowLayout.LEFT, 270, 30));
panelForTitle.add(title);
mainPanel.add(panelForTitle);
mainPanel.add(topPanel);
JPanel tablePanel = new JPanel(new BorderLayout());
tablePanel.setBorder(BorderFactory.createEmptyBorder(15, 25, 15, 25));
tablePanel.add(spTable);
mainPanel.add(tablePanel);
JPanel bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 30));
close.setPreferredSize(new Dimension(90,22));
mapButton.setPreferredSize(new Dimension(90,22));
bottom.add(close);
bottom.add(mapButton);
mainPanel.add(bottom);
bottom.setMaximumSize(new Dimension(600, 0));
setTitle("Mapping Flags");
setSize(new Dimension(650, 380));
setResizable(false);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
另一类
public void setMappingsTable(){
dtm = new DefaultTableModel(new String[]{"Style ID", "Style", "Exact Match", "Carry Over", "OEM Temp"}, 0);
mappingsTable.setModel(dtm);
mappingsTable.setRowHeight(20);
mappingsTable.getColumnModel().getColumn(0).setPreferredWidth(75);
mappingsTable.getColumnModel().getColumn(1).setPreferredWidth(410);
mappingsTable.getColumnModel().getColumn(2).setPreferredWidth(130);
mappingsTable.getColumnModel().getColumn(3).setPreferredWidth(130);
mappingsTable.getColumnModel().getColumn(4).setPreferredWidth(130);
mappingsTable.setFont(new Font("SansSerif", Font.PLAIN, 12));
mappingsTable.setBackground(Color.WHITE);
Color color = mappingsTable.getGridColor();
// mappingsTable.setBorder(new MatteBorder(0, 0, 0, 0, color));
mappingsTable.setBorder(BorderFactory.createLineBorder(Color.RED,1));
addDataToTable();
}
public JScrollPane setScrollPane(JTable mappingsTable){
spTable = new JScrollPane(mappingsTable);
spTable.setBounds(45, 230, 700, 300);
// spTable.setBorder(BorderFactory.createEmptyBorder());
return spTable;
}
我能做些什么以添加在头边框或删除底部,左,右不在JScrollPane的数据的部分章节?谢谢你的帮助。看起来不管我做什么都不完美,我需要什么。
我想只是将边框添加到标题,但我不确定如何做到这一点。 – Steller
@Steller,我刚刚告诉过你该怎么做。有两个步骤1)从表格中获取表格标题。 2)将MatteBorder添加到标题。你不明白哪一步? – camickr
我明白了,谢谢! – Steller