Bad Checkbox UI : CheckBox Button « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
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. Swing CheckBoxesSwing CheckBoxes
2. CheckBox Demo 2CheckBox Demo 2
3.  How to use the check box button How to use the check box button
4. CheckBox MnemonicCheckBox Mnemonic
5. React to menu action and checkbox menuReact to menu action and checkbox menu
6. Swing CheckBox DemoSwing CheckBox Demo
7. CheckBox Item ListenerCheckBox Item Listener
8. Icon CheckBox DemoIcon CheckBox Demo
9. Flat CheckBoxFlat CheckBox
10. Radio button, ComboBoxRadio button, ComboBox
www__.__j___a__v__a_2_s__.___c__o__m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.