Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTextField with custom border and margin insets

843806May 8 2008 — edited May 8 2008
Yello,
What should have been a simple process...
I created a class which extends JTextField.

In the constructor, I want this class to have a line border with whatever color and a left inset of 10.
However, setting a custom border ignores the setMargin(). If I remove the border line, the margin shows up fine.
Is there a way to accomplish both?

This is what I thought should work:
...
LineBorder border = new LineBorder(new Color(100, 100, 100), 1);
this.setBorder(border);
this.setMargin(new Insets(0, 10, 0, 0);
...
I tried the following, but it doesn't seem to work either:
LineBorder border = new LineBorder(new Color(100, 100, 100), 1);
Insets insets = border.getBorderInsets(this, new Insets(0, 10, 0, 0));
this.setMargin(insets);
What am I doing wrong? =)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 5 2008
Added on May 8 2008
5 comments
993 views