问题:
I have a JTable with a JScrollPane that makes sure there's a scroll bar in case it becomes too large. It all works perfectly fine, and here's a screenshot of it:
You c...
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
I have a JTable
with a JScrollPane
that makes sure there's a scroll bar in case it becomes too large. It all works perfectly fine, and here's a screenshot of it:
You can't see the scrollbar right now because it's not necessary, but that's not the problem. The problem is around the JTable
and lower (revealing the size of the JScrollPane
), you can see a border that kind of makes it look 3D with a shadow and such. I wish to remove this. I can't seem to find any property that disables this and both the JTable
and JScrollPane
have no border of any kind (no default either). Any ideas on how to remove this 3D border?
回答1:
It's hard to say since you show no code, but do both getBorder() and getViewportBorder() return null when called on the JScrollPane (not the JTable).
Which LnF (look and feel) are you using?
回答2:
jScrollPane.setBorder(new EmptyBorder(1, 1, 1, 1));
jTable.setBorder(new EmptyBorder(1, 1, 1, 1));
Use your own variable names relevant to "jScrollPane" and "jTable". It is better to use Windows Look and Feel to have a good look.
回答3:
I found that this 3D border was actually generated by the Default look and feel. By changing this, I was able to remove the border.
回答4:
In LookAndFeel initialization just set empty border:
UIManager.getDefaults().put("ScrollPane.border", BorderFactory.createEmptyBorder());
UIManager.getDefaults().put("Table.border", BorderFactory.createEmptyBorder());
It will affect all ScrollPane objects around your applicatin, if you wanto t change just single one use this code:
jScrollPane.setBorder(BorderFactory.createEmptyBorder());
jTable.setBorder(BorderFactory.createEmptyBorder());
In case you want to save top line border for header use MatteBorder:
BorderFactory.createMatteBorder(1, 0, 0, 0,Color.LIGHT_GRAY))//1 is top line, rest is empty