jList in Scrollpane, seeking and displaying value of selectedIndex - java

I have a JList inside a Scrollpane. If you click on the list and move the arrow keys up and down it works like you expect, you can move your selection index and display around just fine.
Now, what I want to do is basically have a text box and i'm typing in the text box like "comic" and want it to seek to the index of that value. This WORKS just fine.
Where the problem is when the value of the list box is below, or above the viewable area. When it is, the selected index seeks, but does not change the position of the scrollable region. However, if I press the up or down arrows and requestFocus() to the list, and move up and down it seeks to the right viewable area.
What am I missing to make this happen WITHOUT changing focus. I want to be able to just type in the list all I want and have it show me what is selected. I feel i'm missing something obvious here.

If I understand the question then you should be able to use:
list.setSelectedIndex(...);
list.ensureIndexIsVisible(...);
If that doesn't help then post your SSCCE demonstrating the problem.

Related

StyledText nullpointer

Im working with SWT StyledText to display data to the user in one part of the window. In another part I have a graph, over which I slide my mouse pointer. As I slide my mouse over a point in the graph, it highlights the corresponding entry in the StyledText Area.
I want my textArea to automatically scroll to the newest change, so I am using .setTopIndex().
To determine the index I need to be able to look at which entries in the textArea changed from not highlighted to highligted, I use the following (to check if my styleRange changed):
styledText.getStyleRangeAtOffset(offset)
So far my program functions correctly. My next check is:
styledText.getStyleRangeAtOffset(offset).isUnstyled
or
styledText.getStyleRangeAtOffset(offset).foreground
or something like that. Here enters the problem. When I call any of these I get a nullPointerException.
Thank you for all the pointers :) after some debugging I discovered that the unedited styleRange is null. That explains the nullPointer I kept on receiving

Can JTable be resized by the user dragging the mouse

So I am creating a GUI and it has a JTable that is set inside of a JScrollpane. When the user opens the window it displays everything how I want it to. The user can add rows to the table to fill in data and then they can scroll through the information. I also have a JButton which I have set to print the whole window. Now my problem is the table prints but only shows the data in the viewing area. What i was thinking was if the user could drag the bottom corner of the JTable to re size it to show everything then everything would be ok, I'm just not sure if that's even possible or how to do it. Ive been searching and i haven't seem to come across anything like this yet.
Edit:
So for anyone else here is the link to the class I found. It allows you to use the mouse to resize any component.
http://tips4java.wordpress.com/2009/09/13/resizing-components/
To get an image of the entire table you can try using Screen Image, which allows you to take an image of a specific component.

Creating a checkbox java list

i am trying to generate a checkbox list feeded by some records from a database just like the image (JAVA Swing), initially i tried with several chexkboxes but it didn't work, now i am trying with a multiple selection list but it didn't work as well and none of the answered questions here looks like to solve the specific needs i have.
Specifications:
Multiple selection list.
Every node of the list must have a checkbox object.
When checked every node must stay highlighted.
It must have an scrollbar if the content is bigger to the initially setted dimentions.
It must have an scrollbar if the content is bigger to the initially set dimensions.
Put the JList inside a JScrollPane.
When checked every node must stay highlighted.
This is going to confuse the user. The check marks are sufficient.
Every node of the list must have a check box object.
You'll have to extend a JList and a ListCellRenderer to gain this functionality. The ListSelectionListener that I have is over 100 lines of code.
You might find an already existing check box JList on the web. I have one in a book.

Inline menu appearing with mouseover

What I am looking for is an inline menu, that pops up by a mouseover event. Does anyone know how to do something like this? The way it currently works in my program is very complicated (using multiple servlets and JSON).
Answered
create a div element that will house the menu items that you require. hide it by default and give it absolute positioning. Add a mouseover event that will calculate the position based on which element you are hovering over and set this element's position to that and make it visible.

How to change the image by click keyboard arrows?

I have made one project in java. Now in this particular module, i am showing the user , so i am showing them a stock inventory.
Now for doing this.
As you will see in the screen shot [ i have put screenshot so you can understand well ].
To show the images , i have made one table and i have put labels in that and then i am setting the icon at the label.
Now as soon as user click on the any image, then that image i put on big label.
But this works perfect on mouse click but client want that , if user navigate the by keyboard arrow keys then in same should be happen.
Means : User navigate by key board then it should reflect on that table [user should know that which is currently seleted ] and then as soon as the user navigate by key board arrow events and then click enter then that image should reflect on big label.
Here is the Link for that screenshot.
Sounds like there are two steps in what you need to do.
First, the user needs to know which image is selected. Unfortunately I can't help you with that, since I don't know how you're displaying that grid. From a UI point of view, I'd suggest exploiting that white border you've got in each cell -- change it black, blue, or whatever color you like to indicate that it's the selected cell. You seem to be using a JTable, in which case you can write a TableCellRenderer (probably by extending DefaultTableCellRenderer) and call its setBackground() method.
Then you need to listen for keyboard input. This part shouldn't be too bad; write a KeyListener and add it to the JTable itself. For each key event, see if the key code matches the arrow keys; if so, move your cursor around accordingly. Don't forget to watch out for the edges of the JTable.

Categories

Resources