Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #178

Re: Highlight itemin JLis

From "usenet" <usenet@THRWHITE.remove-dii-this>
Subject Re: Highlight itemin JLis
Message-ID <4T3la4akInu5@uni.chka.de> (permalink)
Newsgroups comp.lang.java.gui
References <9_n5h.217903$Ry4.146642@newsfe10.phx>
Date 2011-04-27 15:26 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
Knute Johnson <nospam@rabbitbrush.frazmtn.com> wrote:
> Java and Swing wrote:
> > I have a JList which I add a MouseListener to. When the mouseEntered
> > method gets called I'd like to select the item in the JList for which
> > the mouse is over. 

> I thought this was going to be difficult, turns out it is pretty simple.

>          JList list = new JList();

>          list.addMouseMotionListener(new MouseAdapter() {
>              public void mouseMoved(MouseEvent me) {
>                  Point p = new Point(me.getX(),me.getY());

Eh, MouseEvent.getPoint().

>                  list.setSelectedIndex(list.locationToIndex(p));

Probably setSelectedIndex(-1) is not valid -- this occurs (only) if there
are no items.




Also see: http://groups.google.com/group/comp.lang.java.gui/browse_frm/thread/1f9886beebe795b



Christian

---
 * 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 | NextPrevious in thread | Find similar


Thread

Highlight itemin JList on "Java and Swing" <java.and.swing@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
  Re: Highlight itemin JLis "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
    Re: Highlight itemin JLis "usenet" <usenet@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000

csiph-web