File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a checkbox border

 
Sarone Thach
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
m_checkbox.setText(sTitle);
m_checkbox.setSelected(bSelect);
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
{
super.paintBorder(c,g,x,y,width,height);
g.setColor(Color.white);
g.draw3DRect(9, 4, 12, 12, false);
}

public boolean isSelected()
{
return m_checkbox.isSelected();
}
}
 
Brian Pipa
Ranch Hand
Posts: 299
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Brian
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic