Skip to content

Commit

Permalink
Ensure Graphics2D is disposed.
Browse files Browse the repository at this point in the history
Change rollover color cross to blue.
  • Loading branch information
Borewit authored and Borewit committed Feb 5, 2023
1 parent 5f59752 commit 71b7237
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/main/java/listfix/swing/JButtonTabComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,28 @@ protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
//shift the image for pressed buttons
if (getModel().isPressed())
try
{
g2.translate(1, 1);
//shift the image for pressed buttons
if (getModel().isPressed())
{
g2.translate(1, 1);
}
g2.setStroke(new BasicStroke(2));
g2.setColor(Color.BLACK);
if (getModel().isRollover())
{
g2.setColor(Color.BLUE);
}
int delta = 6;
g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
g2.dispose();
}
g2.setStroke(new BasicStroke(2));
g2.setColor(Color.BLACK);
if (getModel().isRollover())
finally
{
g2.setColor(Color.MAGENTA);
g2.dispose();
}
int delta = 6;
g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
g2.dispose();
}
}

Expand Down

0 comments on commit 71b7237

Please sign in to comment.