• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Location Finding in a List

 
Matthew Gaunt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There,
What I am trying to do is create an applet which has a list box holding a list of names which is obtained from a database. That is the easy bit.
When this is being displayed on the screen, as the mouse pointer moves over the names in the list, a Javascript popup box detailing more information is displayed. This is a little more difficult, but it is working for the most part.
The way the program knows what name the pointer is over is by finding out the x,y co-ordinates of the mouse position inside the List box, and determining which name it would be over at that position. (determining font heights and so on)
However, if the number of names in the list is more than the area allowed for it, a scrollbar is automatically added (as would be expected).
The problem is that after the scrollbar has been adjusted, I cannot work out how to determine which name the pointer is hanging over in the list. This is made even more difficult by the lack of an addAdjustmentListener() method for the List object.
Does anyone have any ideas.
Thanks
Matt
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be so much easier to have the JavaScript popup when a name in the list is selected. Does it have to be on the mouseover?
 
Matthew Gaunt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, the client really does want it on the mouseover.
But not to worry, as sorted it out by putting the list of things in a list box big enough to contain all of the names without a scrollbar, and then adding that list to a scrollpane. The list box had a mousemotionlistener added to it, and the index of the name the mouse was scrolling over was determined by dividing the y position by the font height.
Not the most efficient way, but effective none the less.
Best Regards
Matt Gaunt
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just some idle and useless thoughts.
Why not have a vertical panel of labels instead of list? The caption of the label would act as a list item. To give the panel the appearance of a list, the label background could be set to white. The advantage would be that the mouse motion listener could be attached to each label, and the popup action could easily be determined by determining the event source label. Maybe this is more robust than dividing Y position by the font height?
Of course the label will have to be subclassed and its paint method overridden to be able to imitate the appearance of a unselected and selected item in a list, and it will have to retain an isSelected state.
Using a separate component for each item could also confer other advantages. Each item can have a distinct appearance- eg. it may have a distinct icon. Also, apart from popup the item itself could change appearance on mouse-over eg. font of that item may become bold or red or whatever or it may become animated.

[This message has been edited by Rahul Rathore (edited April 03, 2001).]
 
Matthew Gaunt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This piece of code is further complicated by the need to integrate it with an application known as SameTime.
Although I didn't consider a list of labels, when I think about it, I probably still would have gone with the list, as it integrates more easily with SameTime. Also, people will enter and exit the applet as the page is loaded, so I feel that the regular creation and destroying of new Label objects as people come and go would end up using too much processing time.
Thank you very much for your suggestion though, and you are quite correct in that I should have thought about this as an option in the very beginning.
Best Regards
Matt Gaunt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic