Bad Checkbox UI : CheckBox Button « Swing JFC « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » Swing JFC » CheckBox ButtonScreenshots 
Bad Checkbox UI
Bad Checkbox UI
  

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicCheckBoxUI;

public class MyCheckBoxUI extends BasicCheckBoxUI implements
    java.io.Serializable, MouseListener {

  private final static MyCheckBoxUI buttonUI = new MyCheckBoxUI();


  public MyCheckBoxUI() {
  }

  public static ComponentUI createUI(JComponent c) {
    return buttonUI;
  }

  public void installUI(JComponent c) {
    super.installUI(c);
    c.setBackground(Color.red);
    c.addMouseListener(this);
  }

  public void uninstallUI(JComponent c) {
    super.uninstallUI(c);
    c.removeMouseListener(this);
  }

  public void paint(Graphics g, JComponent c) {
    AbstractButton b = (AbstractButtonc;
    ButtonModel model = b.getModel();
    Dimension d = b.getSize();

    g.setFont(c.getFont());
    FontMetrics fm = g.getFontMetrics();
    g.setColor(Color.white);
    g.drawString("Am I a check box"1010);

  }

  public void mouseClicked(MouseEvent e) {
  }

  public void mousePressed(MouseEvent e) {
  }

  public void mouseReleased(MouseEvent e) {
  }

  public void mouseEntered(MouseEvent e) {
    JComponent c = (JComponente.getComponent();
    c.setBackground(Color.blue);
    c.repaint();
  }

  public void mouseExited(MouseEvent e) {
    JComponent c = (JComponente.getComponent();
    c.setBackground(Color.red);
    c.repaint();
  }
  public static void main(String[] argv) {
    JFrame f = new JFrame();
    f.setSize(400300);
    f.getContentPane().setLayout(new FlowLayout());

    JPanel p = new JPanel();
    JCheckBox bt1 = new JCheckBox("Click Me");
    bt1.setUI(new MyCheckBoxUI());
    p.add(bt1);
    f.getContentPane().add(p);
    WindowListener wndCloser = new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    };
    f.addWindowListener(wndCloser);
    f.setVisible(true);
  }

}


           
         
    
  
Related examples in the same category
1.JCheckBox is a widget that has two states. On and Off.
2.Swing CheckBoxesSwing CheckBoxes
3.CheckBox Demo 2CheckBox Demo 2
4. How to use the check box button How to use the check box button
5.CheckBox MnemonicCheckBox Mnemonic
6.React to menu action and checkbox menuReact to menu action and checkbox menu
7.Swing CheckBox DemoSwing CheckBox Demo
8.CheckBox Item ListenerCheckBox Item Listener
9.Icon CheckBox DemoIcon CheckBox Demo
10.Flat CheckBoxFlat CheckBox
11.Customizing the Icons in a JCheckBox Component
12.Customize these disabled icons
13.Set pressed icon
14.Display an icon when the cursor is moved over the checkbox. This is called the rollover icon.
15.Adding an Icon to the Label of a JCheckBox Component
16.Getting and Setting the State of a JCheckbox Component
17.Creating a JCheckbox Component
18.Check boxes with item changed event.
19.Get or set the selection state of JCheckBox
20.Customize JCheckBox icons
21.Radio button, ComboBoxRadio button, ComboBox
22.Using CheckBox ActionListener to controll font
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.