How to remove 3D border on JScrollPane

问题: 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:

Screenshot

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
  • 发表于 2019-01-02 17:36
  • 阅读 ( 288 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除