In my JTextfield validation code, I'd like to change the JTextfield's border to red if there's an error - like the user attempted to enter "blah" instead of a numeric value "342.33".
So I'm doing something like this:
Border defaultBorder = (LineBorder)textField.getBorder();
textField.setBorder(new LineBorder(Color.red));
However, the red border doesn't have the same padding as the default L&F border, so the user's input gets moved 4-5 pixels to the left. I can probaly hack away at the code until I create a border with the same padding as the default JTextField but the spacing is probably different across different L&F's.
What I really want to do is this:
Border redBorder = new LineBorder(Color.red);
redBorder.setPadding(defaultBorder.getPadding());
Or..
Border redBorder = defaultBorder.clone();
redBorder.setForeground(Color.red);
But neither the Border Interface or the BorderFactory class seems to support anything like this.
To sum it up, all I want to do is change the JTextfield's border color to red without changing any other properties of the Border.
Any suggestions?
Thanks!