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.
Related
I need your help guys.
I am currently working on a simple JTable in Java with 3 Columns and 128 rows. Now there is one problem i cannot solve at the moment. The thing i want is that when I click on a single cell it changes its background color to Green.
So i need to implement a MouseListener which reacts to the selected cell and sets its background to green. Sort of a "CellListener" I mean.
I've tried so many things and searched many blogs etc. but none of them gave me a satisying answer.
Do you have any tips for me?
I doubt you will find a direct link between you being able to click on the table and it respond. Because JTables aren't going to listen out for it like that. If you want to do this. You will need an intermediate step. I would suggest that you use the mouse listener to get the mouse location on the screen when the user clicks. And then check IF that location is the same as a particular cell of the JTable.
I am working on an application that uses a TableView and has a Table Menu Button to add or remove columns from the list.
Since I wanted my column headers to have tooltips, I had no choice but to create a label and use it in the following manner in :
// Some code here
TableColumn col;
// some code here
col.setGraphic(header_title);
The problem with this is that when the program runs, the table menu button shows a list of empty text:
On the other hand when I do:
// Some code here
TableColumn col;
// some code here
col.setText(rs.getString("column_title"));
col.setGraphic(header_title);
I can see the text on the column menu, but the actual titles are appended to the graphic:
I have tried to look for a way to perform a setContentDisplay(GRAPHIC_ONLY), but this does not seem to exist for TableColumn, and I am not sure how to access the header node in order to set this setting.
Any help would be greatly appreciated.
Just forget about the inbuilt table menu button. It's absolutely minimal and not worth mentioning. If you e. g. want to click away 10 columns you have to click on the button, hide the column, click on the button, hide the column, etc. In other words: It closes as soon as you press a menu item.
You can't even extend it with e. g. a hide all and a show all button. And it's buggy: When the last column gets hidden, the menu button vanishes as well, so you have to restart your application if you want to see anything in your table again.
Just create your own table menu. There are 2 examples on this gist:
example which uses a lookup, i. e. works without reflection
example which uses reflection
Then you can adapt whatever header you want and whatever menu items you want.
I am creating a log in form in Java. I have already completed the entire structure of the program, as well, I have designed it's purpose and perfected it's functionality. However, now I am focusing on styling the program. I'm proud of it as it is and it's fine if I don't add this feature, however I really would like to and cannot discover how.
In summary, when a username is typed into the login form, I have a void that runs after the JTextField loses focus. This void searches for possible invalid characters such as spaces. I can successfully change the color of the border on my JTextField, and other attributes I wish to change, however I also would like to have a small dialogue box to hover over the JTextField to say what specifically is wrong with what was typed. (e.g. "Your username cannot contain spaces!").
Ideally, it would be a rectangle that could simply be filled with text, and only appear when the username is deemed incorrect, and be able to disappear when it is fixed ( I can handle the appearance and disappearance most likely, I just need help with creating this box thing ).
Is there any such thing as like a "JHoverBox" or something that I could add to my JTextField?
Well, you can have, as Gene said, a label that's normally empty near the text field, but you can have it coloured like the background colour. This will make the user not able to see it, and when you detect something wrong, you can change the colour and add the text. Simple!
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.
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.