Hi, I am hoping to get some advice on a problem I am trying to tackle. In my application, I have a single line textpane inside a scrollpane. The user will input some text (that could be longer than the length of the textpane - hence the scrollpane!). What I eventually want to achieve is that if the user clicks on any of the words in the text, I would like to have a slider popup right next to the word. So essentially, I need to find the exact position of the word and put the slider there.
I don't understand what is going on. I am using the location of the mouse using the mouseevent. I am trying to place the slider at the location of the mouse. But when i pass the mouse location information to the jSlider.setLocation(), the x position is correct, but the y position of the slider is way below the position of the mouse. Any clues?
Hi, I have created an SSCCE. I use netbeans to develop my swing application. I have tried to remove most of the automatically generated code which I saw as unnecessary. Hopefully you should see this behaviour when you run the file. Once you run the file click anywhere in the textpane, and you should see the slider move to the same x position as the mouse, but is lower below.
You took out too much. The controls aren't added to the frame anymore.
The call to jSlider1.setLocation(evt.getLocationOnScreen()); will not do what you want though. The layout manager (a GroupLayout) will ignore the position you set, and set it where it thinks it belongs. You will get this behaviour with just about every layout manager.
Rob Camick wrote:Don't use a null layout for you main components.
Use a Glass Pane with a null layout to hold the slider so it paints on top of other components. For example:
Thanks Rob for your suggestion here. It took me a while to get back to this. I worked with Glasspane and it resolved my issue. I am having some issues with some additional behaviour i am trying to implement. but I am working throught it.