I have a JButton that is written using the user delegate of the user interface (CustomButtonUI extends BasicButtonUI). The customButtonUI paint () method draws a button with rounded “smooth” corners to make apperance as smooth as possible.
Somehow the “smoothed” edges of the button disappear every time I drag the mouse over the button. This makes the edges of the buttons look “pixelated”. However, as soon as I add a line of code to recolor the parent of the button, smoothing will hit even when I click the mouse button above the button.
Now, my question is, is this a good idea? I will still repaint the parent component from the child component. I wonder if this led to the appearance of a loop? If a parent is trying to redraw his children, and the children are trying to repaint their parent, then I guess we are talking about a loop.
I linked my code as a link. Any comments are very welcome!
public class JCustomButtonUI extends BasicButtonUI { @Override public void installUI(JComponent c) { super.installUI(c); AbstractButton b = (AbstractButton) c; b.setBorderPainted(false); } @Override public void paint(Graphics g, JComponent c) {
Update 1
To illustrate the alias and the smooth border, please take a look at the two photos below. When I (from the ButtonUI paint () method) manually call the parent JPanel repaint method, all borders are completely smoothed all the time. However, when I do not manually call the parent JPanel repaint method, the borders no longer smooth out as soon as I click the mouse button above the button.


Update 2
I have separated the entire “component”, which consists of JPanel, JSlider and a pair of JButtons on Snipt. Please get it from http://snipt.org/wnllg .
Update 3
I think I managed to get it to work. Instead of painting the JPanel background in my paintComponent () method, I created a JCustomPanelUI that I installed on JPanel. I don't think this was the solution itself, but instead of using the width and height from the Graphics instance, I tried using widht and height from the JPanel itself. I'm not quite sure why something is wrong when I use the width and height from the Graphics instance. I thought that the width and height from the Graphics instance were already “prepared” relative to the dimensions from the JPanel component. You can look at the last component here: http://snipt.org/wnlli ,