要摆脱JTable/JScrollPane的边界,可以使用以下方法:
JTable table = new JTable();
table.setShowGrid(false);
table.setIntercellSpacing(new Dimension(0, 0));
table.setBorder(BorderFactory.createEmptyBorder());
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBorder(BorderFactory.createEmptyBorder());
scrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
scrollPane.getViewport().setPreferredSize(table.getPreferredSize());
scrollPane.getVerticalScrollBar().setUI(new BasicScrollBarUI());
scrollPane.getHorizontalScrollBar().setUI(new BasicScrollBarUI());
table.setRowHeight(20);
table.setIntercellSpacing(new Dimension(0, 0));
JTableHeader header = table.getTableHeader();
header.setBorder(BorderFactory.createEmptyBorder());
header.setBackground(Color.WHITE);
header.setForeground(Color.BLACK);
header.setFont(new Font("Arial", Font.BOLD, 12));
通过以上方法,可以有效地摆脱JTable/JScrollPane的边界,使其更加美观和易于使用。
领取专属 10元无门槛券
手把手带您无忧上云