File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Creating a checkbox border Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Creating a checkbox border" Watch "Creating a checkbox border" New topic

Creating a checkbox border

Sarone Thach
Ranch Hand

Joined: Jun 25, 2003
Posts: 89
Hi everyone,
I'm wondering if anyone knows how to create a checkbox as part of the border.
When you create a border and give it a title, the title appears on the top left of the border. I would like the checkbox to appear before the title. I also need to get events from the checkbox, whether it has been enabled or disabled.
I have started writing the class, but I'm sure there is a better way to draw the check box so that it looks like a checkbox, with event listeners, so that the tick is drawn if selected. Any ideas? Thanks, Sarone.

import javax.swing.border.TitledBorder;
import javax.swing.border.Border;
import javax.swing.JCheckBox;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Color;
public class CheckboxBorder extends TitledBorder
JCheckBox m_checkbox = new JCheckBox();
public CheckboxBorder(Border border, String sTitle, boolean bSelect)
super(border, " "+ sTitle);
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
g.draw3DRect(9, 4, 12, 12, false);

public boolean isSelected()
return m_checkbox.isSelected();
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
I saw a free class recently that did exactly that. I thought about using it in some of my apps. Unfortunately, I didn't bookmark it. I found the link to it in the Swing forum (I think). It was a page with a bunch of cool exanples of Swing stuff. Check or ask in the Swing forum.

My Java Freeware:<br />MACCC - <a href="" target="_blank" rel="nofollow"></a><br />Nator - <a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: Creating a checkbox border
It's not a secret anymore!