From: Jim Janney on
Knute Johnson <nospam(a)rabbitbrush.frazmtn.com> writes:

> From: Knute Johnson <nospam(a)rabbitbrush.frazmtn.com>
> Subject: Re: dynamic tool tip text
> Newsgroups: comp.lang.java.programmer
> Date: Thu, 18 Mar 2010 10:16:51 -0700
> Organization: NewsDemon
>
> On 3/18/2010 9:32 AM, Jim Janney wrote:
>> Thanks. That still doesn't work with a JComboBox, but that turns out
>> to be because nothing works with JComboBoxes, as is copiously
>> described in bug ID 4144505, where Sun says "yes we know, but we're
>> not going to fix it."
>
> Sure it does.
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> public class test extends JPanel {
> String[] items = {"One","Two","Three","Four","Five"};
>
> public test() {
> super(new GridBagLayout());
>
> setPreferredSize(new Dimension(400,300));
>
> JComboBox b = new JComboBox(items);
> b.addMouseListener(new MouseAdapter() {
> public void mouseEntered(MouseEvent me) {
> JComponent c = (JComponent)me.getSource();
> if (me.isAltDown())
> c.setToolTipText("ALT is pressed");
> else
> c.setToolTipText("ALT isn't pressed!");
>
> }
> });
> add(b);
> }
>
> public static void main(String[] args) {
> EventQueue.invokeLater(new Runnable() {
> public void run() {
> JFrame f = new JFrame();
> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> test t = new test();
> f.add(t);
> f.pack();
> f.setVisible(true);
> }
> });
> }
> }

More precisely, it works on the editor but not on the button.

To be somewhat less unfair to Sun, I did find some discussion of this at

http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html#listeners

> Although JComboBox inherits methods to register listeners for
> low-level events -- focus, key, and mouse events, for example -- we
> recommend that you don't listen for low-level events on a combo
> box. Here's why: A combo box is a compound component -- it is
> comprised of two or more other components. The combo box itself
> fires high-level events such as action events. Its subcomponents
> fire low-level events such as mouse, key, and focus events. The
> low-level events and the subcomponent that fires them are
> look-and-feel-dependent. To avoid writing look-and-feel-dependent
> code, you should listen only for high-level events on a compound
> component such as a combo box. For information about events,
> including a discussion about high- and low-level events, refer to
> Writing Event Listeners.

--
Jim Janney
From: John B. Matthews on
In article <Fcton.11430$%H1.2477(a)newsfe23.iad>,
Knute Johnson <nospam(a)rabbitbrush.frazmtn.com> wrote:

> On 3/18/2010 9:32 AM, Jim Janney wrote:
> > Thanks. That still doesn't work with a JComboBox, but that turns
> > out to be because nothing works with JComboBoxes, as is copiously
> > described in bug ID 4144505, where Sun says "yes we know, but we're
> > not going to fix it."
> > ...
> > We let our users change the L&F at runtime, so I need something
> > that works with that.
>
> Sure it does.

[compelling example elided]

It works well with Metal, Motif & Nimbus, but not the Mac OS UI
delegate, com.apple.laf.AquaComboBoxUI.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Knute Johnson on
On 3/18/2010 12:39 PM, John B. Matthews wrote:
> In article<Fcton.11430$%H1.2477(a)newsfe23.iad>,
> Knute Johnson<nospam(a)rabbitbrush.frazmtn.com> wrote:
>
>> On 3/18/2010 9:32 AM, Jim Janney wrote:
>>> Thanks. That still doesn't work with a JComboBox, but that turns
>>> out to be because nothing works with JComboBoxes, as is copiously
>>> described in bug ID 4144505, where Sun says "yes we know, but we're
>>> not going to fix it."
>>> ...
>>> We let our users change the L&F at runtime, so I need something
>>> that works with that.
>>
>> Sure it does.
>
> [compelling example elided]
>
> It works well with Metal, Motif& Nimbus, but not the Mac OS UI
> delegate, com.apple.laf.AquaComboBoxUI.
>

Is that the default for Mac? Do tool tips work at all on Mac?

Thanks,

--

Knute Johnson
email s/nospam/knute2010/

From: Knute Johnson on
On 3/18/2010 12:11 PM, Jim Janney wrote:
> Knute Johnson<nospam(a)rabbitbrush.frazmtn.com> writes:
>
>> From: Knute Johnson<nospam(a)rabbitbrush.frazmtn.com>
>> Subject: Re: dynamic tool tip text
>> Newsgroups: comp.lang.java.programmer
>> Date: Thu, 18 Mar 2010 10:16:51 -0700
>> Organization: NewsDemon
>>
>> On 3/18/2010 9:32 AM, Jim Janney wrote:
>>> Thanks. That still doesn't work with a JComboBox, but that turns out
>>> to be because nothing works with JComboBoxes, as is copiously
>>> described in bug ID 4144505, where Sun says "yes we know, but we're
>>> not going to fix it."
>>
>> Sure it does.
>>
>> import java.awt.*;
>> import java.awt.event.*;
>> import javax.swing.*;
>>
>> public class test extends JPanel {
>> String[] items = {"One","Two","Three","Four","Five"};
>>
>> public test() {
>> super(new GridBagLayout());
>>
>> setPreferredSize(new Dimension(400,300));
>>
>> JComboBox b = new JComboBox(items);
>> b.addMouseListener(new MouseAdapter() {
>> public void mouseEntered(MouseEvent me) {
>> JComponent c = (JComponent)me.getSource();
>> if (me.isAltDown())
>> c.setToolTipText("ALT is pressed");
>> else
>> c.setToolTipText("ALT isn't pressed!");
>>
>> }
>> });
>> add(b);
>> }
>>
>> public static void main(String[] args) {
>> EventQueue.invokeLater(new Runnable() {
>> public void run() {
>> JFrame f = new JFrame();
>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>> test t = new test();
>> f.add(t);
>> f.pack();
>> f.setVisible(true);
>> }
>> });
>> }
>> }
>
> More precisely, it works on the editor but not on the button.
>
> To be somewhat less unfair to Sun, I did find some discussion of this at
>
> http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html#listeners

I tried this on Windows with 1.6.0_18. It works on both the box and the
arrow button. What OS and Java are you running?

--

Knute Johnson
email s/nospam/knute2010/

From: Jim Janney on
Knute Johnson <nospam(a)rabbitbrush.frazmtn.com> writes:

> On 3/18/2010 12:11 PM, Jim Janney wrote:
>> Knute Johnson<nospam(a)rabbitbrush.frazmtn.com> writes:
>>
>>> From: Knute Johnson<nospam(a)rabbitbrush.frazmtn.com>
>>> Subject: Re: dynamic tool tip text
>>> Newsgroups: comp.lang.java.programmer
>>> Date: Thu, 18 Mar 2010 10:16:51 -0700
>>> Organization: NewsDemon
>>>
>>> On 3/18/2010 9:32 AM, Jim Janney wrote:
>>>> Thanks. That still doesn't work with a JComboBox, but that turns out
>>>> to be because nothing works with JComboBoxes, as is copiously
>>>> described in bug ID 4144505, where Sun says "yes we know, but we're
>>>> not going to fix it."
>>>
>>> Sure it does.
>>>
>>> import java.awt.*;
>>> import java.awt.event.*;
>>> import javax.swing.*;
>>>
>>> public class test extends JPanel {
>>> String[] items = {"One","Two","Three","Four","Five"};
>>>
>>> public test() {
>>> super(new GridBagLayout());
>>>
>>> setPreferredSize(new Dimension(400,300));
>>>
>>> JComboBox b = new JComboBox(items);
>>> b.addMouseListener(new MouseAdapter() {
>>> public void mouseEntered(MouseEvent me) {
>>> JComponent c = (JComponent)me.getSource();
>>> if (me.isAltDown())
>>> c.setToolTipText("ALT is pressed");
>>> else
>>> c.setToolTipText("ALT isn't pressed!");
>>>
>>> }
>>> });
>>> add(b);
>>> }
>>>
>>> public static void main(String[] args) {
>>> EventQueue.invokeLater(new Runnable() {
>>> public void run() {
>>> JFrame f = new JFrame();
>>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>> test t = new test();
>>> f.add(t);
>>> f.pack();
>>> f.setVisible(true);
>>> }
>>> });
>>> }
>>> }
>>
>> More precisely, it works on the editor but not on the button.
>>
>> To be somewhat less unfair to Sun, I did find some discussion of this at
>>
>> http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html#listeners
>
> I tried this on Windows with 1.6.0_18. It works on both the box and
> the arrow button. What OS and Java are you running?
>

Windows, java 1.6.something (I'm at home now, not at work). Try this:
Press the alt key and move the mouse into the box. The tooltip will
show "Alt is pressed". Now move the mouse back into the panel. With
the alt key released, move it into the arrow button. On my system the
tooltip shows "Alt is pressed", because there is no mouse listener on
on the arrow button. If you run this in a debugger you can also try
setting a breakpoint in the mouseEntered method.

--
Jim Janney
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Java Type System
Next: Evisu original jeans Wholesale