Why my JTextField has changed after set new Border

梦想的初衷 提交于 2019-12-24 04:12:42

问题


I would like to know why my element JTextField has change height after setting a new Border:

  packagesAddField.setBorder(BorderFactory.createLineBorder(Color.RED));

after this code my JTextField changing a height (about 1px from upper and 1px from footer). It is possible, when i set some border he can change appearance of component?


回答1:


In a word, don't. The setBorder() API recommends that you add the border to the enclosing container:

Although technically you can set the border on any object that inherits from JComponent, the look and feel implementation of many standard Swing components doesn't work well with user-set borders. In general, when you want to set a border on a standard Swing component other than JPanel or JLabel, we recommend that you put the component in a JPanel and set the border on the JPanel.

Alternatively, consider an InputVerifier.



来源:https://stackoverflow.com/questions/24850292/why-my-jtextfield-has-changed-after-set-new-border

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!