As from subject, I have an awt.List object. When I add something to the list I would like to scroll it down to show the last inserted object.
For instance:
myList.add("sometext");
myList.select(myList.getItemCount()-1);
myList.showSelectedItem(); // Or something like that
The documentation does not seem to list any method that does something like that, can anybody help please?
I am not sure that this is possible (explicitly). In my experience I have written an app for a Windows Mobile device using AWT and when I used one JVM calling myList.select(myList.getItemCount()-1); was enough to get it to scroll to that item, but as soon as I switched to another JVM it did not do it. So it is implementation dependent but I think there is no requirement in the specification that says that a List field should do this.
My workaround was simply to reverse the List, so that new items were added at the top. Understandably this is not ideal for all situtations, but in my case it was fine.
I use the makeVisible(index) call where index is the index of the item that is selected. This scrolls the listbox down until the selected item is visible. I'm using JDK 1.6.0_65 on Mac OSX 10.8.
Related
I want to run the example from the official Vaadin vendor site:
https://vaadin.com/components/vaadin-grid/java-examples/drag-and-drop
Of course, I have some other objects to drag, but i am happy when the example is working. At the minute, I don't know how it is meant to be used, or I am getting dumb, because I am living in germany.
I wonder why the example is not running out of the box.
When i use this code, there are several errors in the code. What is dragItems? And how to calculate the index of the drop position? Any help is appreciated. I just want to use this framework, but the demos are not compiling.
I want to drag an item from a grid on another grid. How to do that?
These fields are missing in the code:
private Collection<Person> draggedItems;
private Person draggedItem;
private Grid<Person> dragSource;
You can check the full code here for Vaadin 14: https://github.com/vaadin/vaadin-grid-flow/blob/4.3/vaadin-grid-flow-demo/src/main/java/com/vaadin/flow/component/grid/demo/GridDemo.java#L2375
draggedItems is the list of items that you started to drag (they are set on GridDragStartEvent and cleaned on GridDragEndEvent)
You are dropping the items on an item (before or after). The index of the position has to be calculated. It depends if you are using a listDataProvider or something else.
I'm developing new module in our application using vaadin14 components (eg https://vaadin.com/components/vaadin-date-picker). Everything worked pretty well, but after adding few components (text fields, grids, buttons, labels, notifications etc..) vaadin decided to not listen to me anymore... ;(
Everything started when I've tried to add some addon - slider (because for some reason it was removed from vaadin14). Even I tried a bounch of different addons none of them seem to work, it always lead to not displaying component(it was visible in html code when I was checking html elements on website, but size of that elements always was 0x0 - even setting its size in style didn't seem to work, because - yes it took some place on gui, but was invisible).
I thought that it might be some issue with my vaadin version or some deprecated addons and I've returned to work with default vaadin components. But this time it not seem to work as well. Currently the same issue is with IntegerField, NumberField, DatePicker, ProgressBar and I think that there is much more. There are no errors in console, no errors from server side, html elements are visible in generated html but its size is always 0x0 or not visible(eg vaadin-data-picker 0x0 data-picer 0x0).
Eg.:
html egxample
Like you can see there are no styles visible or whatsoever..
Code that should generete them looks like that(it is taken straight from vaadin example):
IntegerField integerField = new IntegerField("Age");
integerField.setSizeFull();
integerField.setVisible(true);
add(integerField);
NumberField numberField = new NumberField("Years of expertise");
numberField.setSizeFull();
numberField.setVisible(true);
add(numberField);
DatePicker labelDatePicker = new DatePicker();
labelDatePicker.setLabel("Label");
DatePicker placeholderDatePicker = new DatePicker();
placeholderDatePicker.setPlaceholder("Placeholder");
I've tried everything - using .setSizeFull(), setVisible(true), rebuilding project with mvn clean install (production and dev mode), deleting node_modules, targer, webpack.generated.js, package-lock.json(both on main directory and module directory) to let vaadin recreate them. But nothing seem to help. On different machine we was able to display NumberField after few rebuilts, but after few more it disapears again...
Thank you in advance!
EDIT:
Check the difference between working and not woring element:
Working element
Not working elements
Like you can see above in working element is bunch of stuff like shadow-root, styles, div etc. I assume that other elements also should consist such.
Try with setSizeUndefined() or use fixed sizes instead, or make absolutely sure all the parent layers also have full size.
When you use setSizeFull() you are telling the component to spread out to use all the available space, but if there is any container parent in there that has undefined size, that one will only use as much space as the contents demand -- which is nothing, if the contents are all set to full size. All the available space of nothing is nothing.
Is anyone familiar with a debugging option that has the feature? I have a list of items in a JComboBox deeply embedded in a swing app that is buried withing multiple lists. Is there is away to find the index of these items in the Eclipse Debugger without writing code? I could manually write down the index of every list, but I'm looking for an easier way to tell me that this location is at parent[2].layer[0].child[3].layer[1].child[0].combobox[4].item[5]
without looking scrolling through the variable list.
Thanks!
When debugging, in the variables/Expressions pane, at the top right there should be a button with an arrow going to the right called "Show Logical Structure".
If you tick/untick that it should change the display of list structures. It might help you out.
I have a large set of data from which the user has to select one. I'm thinking of a way to implement it (of course, in a GUI). I have a few ideas. But just thought of posting here as there may be better alternatives..
Say, user has to select a name from a large set of user base. If I simply put a text field for user to enter the name, then there can be issues like entering same name in different formats, misspelling etc...
I see two options here
Using a combo box
Using a list (Actually i'm thinking of something like a tool tip. As I cant show the whole list always due to space issues)
But combo box won't be much user friendly i guess. As the user will have to scroll around the whole list to select an entry. If the number of entries are too large, this will be
Which means, now I'm left only one option. A popping up list, which will change the content according the text user is entering in the text field. So he can type first few letters and the list will show all the entries starting from the entered text. Got my point, right?
Are there any other better to achieve this kind of need?
If I'm going to implement above, what will be the best way to follow. I'm thinking of extending the JTextField to add required functionality. Well, I'll put some method to set the popup list entries. And I'll add some actionListner to watch the text field, and control the popup list accordingly...
Autocomplete is what you are probably looking for. Google for "java swing jcombobox autocomplete" and limit results for the last couple of years to get relevant results. There will be a lot of examples and ideas on how to implement this with custom code.
I believe there is also some custom libraries like "swingx" that provide at least partial or full implementations to save time.
http://swingx.java.net/
They have released code as recently as the beginning of this years so it appears active and might have what you need.
You could take a look at SwingLab's autocomplete feature, it allows you to attach it to a JCombBox, JList or JTextComponent
use AutoComplete JComboBox/JTextField
based on Standard Java Classes
no issue with larger sets of data
no issue with Focus, BackSpace Key, Caret
for better performance to required sort the array before use
simple workaround for setStrict(true/false), restrict input to array
I'm using the StarTeam java API (v10.4).
I am having a heckuva time trying to find which specific revisions a Label is applied to. What makes this tricky is that there seems to be no method on the Label object which provides a list of what that label is applied to.
So you (seemingly) need to go backwards and find a list of items that you want to check for a particular Label, e.g.
int[] check_these_items = new int[]{ item_to_check.getID() };
int[] labelledItems = myLabel.getLabeledItemIDs(check_these_items)
First, that's kind of convoluted because you need to have a Label in the first place when really what I wanted was to get a list of labels attached to a single revision. But ok, let's go with that for now. So now I need to find a single revision from the history. Let's make this simple and say I want to get the third (or fourth) revision:
Item specific_child = item_to_check.getHistory()[3];
Now the problem is that this new child from history has the same ID (via getID()) as the parent so using getLabeledItemIds(check_these_items) will return the same labels and essentially, we haven't gotten anywhere.
I did find a question related to finding past revisions but it wasn't pertaining to finding labels on past revisions.
Of course, I checked Borland's API documentation but have not come up with the solution.
I know the UI can do it so certainly there is way, I'm just having a time finding it.
Any suggestions even at a high-level would be greatly appreciated!
Once you have the Item and the Label at hand, use getFromHistoryByLabelID(int)
to "Returns the specified version of this item based on the given label ID"
This still doesn't seem like the right answer, but eventually I had to move on and ended up using a workaround of finding the revision date/time of the label I wanted and then comparing the item revision to that. So by that type of reverse logic, I was able to check each label attached to the element and find which revisions had that label.