Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1375
| From | "bcr666" <bcr666@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: JRadioButton, JCheckB |
| Message-ID | <1175539249.946061.41550@p15g2000hsd.googlegroups.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <YnbQh.288786$Ju2.278405@newsfe16.lga> |
| Date | 2011-04-27 15:32 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
On Apr 2, 12:50 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> bcr666 wrote:
> > I have a need to disable various JCheckBox and JRadioButton objects.
> > When they are disabled however, I want an "Unavailable Cursor" and I
> > want the object drawn normally (while being unclickable).
>
> > I have subclassed the objects in question, and added this method.
>
> > public void setEditable(boolean editable) {
> > this.editable = editable;
> > if (editable) {
>
> > this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
> > super.enableEvents(Event.MOUSE_DOWN | Event.MOUSE_UP);
> > } else {
> > this.setCursor(CursorFactory.createUnavailableCursor());
> > super.disableEvents(Event.MOUSE_DOWN | Event.MOUSE_UP);
> > }
> > }
>
> > The super.disableEvents() methods however don't seem to do anything in
> > my case.
>
> I don't really understand all of the relationships in the event
> processing but the code below will do what you want. Just for my
> curiosity, why don't you want the components to look disabled?
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> public class test6 extends JFrame {
> public test6() {
> setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>
> class KCheckBox extends JCheckBox {
> boolean state = true;
>
> public KCheckBox(String label, boolean state) {
> super(label,state);
> }
> public void processMouseEvent(MouseEvent me) {
> if (state)
> super.processMouseEvent(me);
> else
> return;
> }
> public void en(boolean state) {
> this.state = state;
> }
> }
>
> final KCheckBox kb = new KCheckBox("JCheckBox",true);
> add(kb,BorderLayout.NORTH);
>
> final JButton b = new JButton("Disable");
> b.addActionListener(new ActionListener() {
> public void actionPerformed(ActionEvent ae) {
> String ac = ae.getActionCommand();
> if (ac.equals("Disable")) {
> kb.en(false);
> b.setText("Enable");
> } else if (ac.equals("Enable")) {
> kb.en(true);
> b.setText("Disable");
> }
> }
> });
> add(b,BorderLayout.SOUTH);
>
> pack();
> setVisible(true);
> }
>
> public static void main(String[] args) {
> new test6();
> }
>
> }
>
> --
>
> Knute Johnson
> email s/nospam/knute/
Like a glove!!! Thanks, this works very well for my purposes. The
reason I don't want them to look disabled, is that they show the state
of my other objects, and when they are disabled (at least in the
windows look and feel), it is hard to see what they are indicating.
Hence why I put up the "unavailable" mouse when they are hovering over
the control.
I tried this using the glasspane method found in "Swing Hacks", but I
found that using a glasspane to trap mouse events, can make it
difficult to use a JSplitPane, and there were some focus issues with
it.
Again Thanks.
P.S. I find it ironic that you named your subclass the same thing I
did.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Find similar | Unroll thread
JRadioButton, JCheckBox d "bcr666" <bcr666@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: JRadioButton, JCheckB "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: JRadioButton, JCheckB "bcr666" <bcr666@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
csiph-web