How to move up/down an item in a table - java

Following is an UI:
There is an Up button and a down button in the UI, when clicking the Up/down button, the selected item(e.g. lib/logger.jar) in the left table(I assume it is a table, because I will create a table to show the items in my Application) will be moved up/down.
Question: How to add function to the Up/Down button, so the item in the table will be moved after clicking the Up/Down button?
BTW, I am using Java SWT/JFace.

If it is a table, you will work with TableItems. To move a TableItem, you have to dispose the one you want to move and create a new one using the constructor that receives an index as one of its arguments. This index is where the new TableItem will be placed.

Related

How to navigate through Vaadin grid and select an item using keyboard?

I'd like to know if it's possible to navigate through Vaadin grid or treegrid and select an item using only keyboard arrow keys? From what i've seen while testing the components, the default behavior seems to be either to move only to one specific cell in grid or to a specific row in treegrid. Selection can be achieved if the user presses spacebar.
I've tried to add a shortcutListener to grid but it doesn't seem to work with arrow keys. And the grid scrollbar doesn't move with the selected item.
grid.addShortcutListener(new ShortcutListener("Down", KeyCode.ARROW_DOWN, null) {
#Override
public void handleAction(Object sender, Object target) {
//..//
selectedItem = dataSource.get(currentSelectedItemIndex);
grid.select(selectedItem);
grid.scrollTo(currentSelectedItemIndex); // this doesn't seem to do anything??
//..//
}
});
I guess my problem is that i don't know how to acquire event that moves selection to other cell/row.
Here's an image to represent the problem which i'm facing. The item that has only blue border was selected using arrow keys. I'd like to select an item automatically when user presses arrow keys (Down or Up) without the spacebar.
Image taken from here: https://demo.vaadin.com/sampler/#ui/grids-and-trees/grid/features
Edit1:
I'm using latest version of Vaadin - 8.1.6.
Edit2:
I tried to add couple of listeners to see if i could at least register the movement to the next/previous cell by using arrow up/down but without any luck.
Here's a list of listeners i've tried:
addSelectionListener - only registers selection after spacebar press
or mouse click. Not quite what i'm looking for.
addItemClickListener - only registers selection from mouse click.
addShortcutListener - registers pressed key but it doesn't work with arrows.
Is there any listener that could potentially help me with this issue?
The Grid component has basic keyboard navigation. If you need advanced options, like you have mentioned, for keyboard navigation, I would warmly recommend to test this add-on:
https://vaadin.com/directory/component/gridfastnavigation-add-on

How does clicking on a JList item open a new tab in JTabbedPane?

I have a JSplitPane divided verticlly which contains JList on the left hand side and a JTabbedPane on the right hand side.
The JList varaiable is named jlist1 which contains 4 items.
The JTabbedPane has no tabs by default.
I want that whenever a user clicks on any of the JList item, a new tab should be opened dynamically on the right hand side of JSplitPane(i.e., a new tab opened in JTabbedPane).
I also want to provide a closing button [x] to all dynamically opened tabs.
How can I achieve this?
I also want to provide a closing button [x] to all dynamically opened tabs
Start by reading the section from the Swing tutorial on How to Use Tabbed Panes. There is a working example that shows how to do this.
I want that whenever a user clicks on any of the JList item, a new tab should be opened dynamically
Well any UI should allow the user to either use the mouse or the keyboard to provide an Action. So typically when using a JList you would use a double click with the mouse or Enter with the keyboard.
Check out List Action. It is a simple class that allows you to create an Action that can be invoked whenever the mouse or keyboard is used.
So in your custom Action you would need to add the logic to create a new tab for the selected item in the JList. Start with the simple Action provided in the link and add your custom code.
You need to add a listener that listens to selection events in jlist. You can achieve this by firing a selection event in JList.
You could use javax.swing.event
The JTabbedPane should listen to this event, get the object associated with the event and construct a tab in the listener implementation.

how to display certain rows in JTable

Hello I have a JTable and there a 3 radio buttons at the bottom when the user clicks the buttons I want the JTable to only show certain rows for that button. I've tried deleting the rows when the button is pressed but I get an error when i click the other button that re-adds them. Is there anyway I can just hide the rows when the button is pressed and show them when the other button is pushed?
Is there anyway I can just hide the rows when the button is pressed and show them when the other button is pushed?
Use a RowFilter for your table. So you need some data in the table that you will be able to specify a filter for. Every time you click the button you will need to change the filter for the new requirements.
Read the section from the Swing tutorial on Sorting and Filtering for more information and working examples.
I think the way to go is implementing your own TableModel (preferably by extending AbstractTableModel)

how to remove the content of grid cell in swt?

In my wizard page I am using gridlayout with 3 colums. The 3 column will have remove button. I am using add button for the composite. when i push add button it will add new row to the grid layout.
Now I am trying to add listener to remove button. When I push the remove button it should remove the row in which the remove button is pushed from the gridlayout and should resize the composite.
How to achieve this. And how to get the row index of the gridlayout?
To remove the controls completely you need to call dispose() on each control and then call layout() on the parent composite.
GridLayout does not make any information about the positions of the controls available so you can't really get a row index. It does sound like you might be better using a TableViewer to show a proper table.

JTable cell loses focus after run an action on selected cells if use keyboard shortcut and temporaily disable the JTable

In my JTable I have a number of actions that can accessed via popup menu or by selecting the configured shortcut. Selecting the action from the popup using mouse or keyboard is fine, and I can use the cursor keys to move to a field next to the original selection no problem. However if I use the shortcutkey instead it performs the action okay but I cannnot exit the selected fields afterwards using the cursor keys, because for some reason the focus is now with a component outside of the JTable.
EDIT:When I start the task I change the cursor and disable the JTable, when I complete the task I renable the table and reset the cursor. If I remove the disable code it works, but this then allow the user to make changes to the table which I dont want, and I cannot understand why it only fails when using keyboard shortcut.
Fixed the problem, after renabling the Jtable I needed to call requestFocusInWindow()

Categories

Resources