In Vaadin 8, I have a Grid with columns and rows populated from jsondata using setDataProvider. Now, I have an edit button, upon clicking it user should be able to edit (a few) columns in the Grid.
In Vaadin 8, there are number of ways to incorporate editing in Grid.
There is a builtin feature of row editor, which can be used also in unbuffered mode. This is not equivalent of having the whole column editable, but mimics it pretty well, while you can use Binder for setting fields, validation, etc. There exists also an add-on that helps keyboard navigation with un-buffered editor.
Alternatively you can use the Grid Renderers Collection add-on, that provides set of editable renderers with edit events etc.. This is literaly what you are looking for, column oriented editing. This is useful approach when only few columns are editable.
https://vaadin.com/directory/component/grid-renderers-collection-for-vaadin7
If you use renderers extensively, there will be more widgets for the browser to render, and that will UI possibly slower than using e.g. row editor in un-buffered mode. This depends heavily on your application and use case. I recommend to study multiple approaches and select the one that fits you the best.
Third alternative is to use ComponentColumn feature, see chapter Component Renderer in Vaadin documentation. This is somewhat easier than implementing custom renderers, but adds some further overhead.
Related
I want to make an app, which will work as interface to several servers.
Why: In web iface provided by default (and we cannot change it) are few things we miss, few could be done better and for sure automation of some stuff would make the job easier.
What do I have: almost finished classes for communication with web interface of a server app.
GUI description:
For some kind of version 0.1: text field for username, radio button to select server and one "go" button. Then several (4-12) action buttons to operate on data, 2x text area with results, one label with some text data - I can manage this.
Then I need to view the data - grid MxN which will load the data, expected size: 7-15 columns, usually 10 rows or less, but rarely it can go over 1k (or even more, but I don't need all to be visible to the user in that case).
What I need: simply an advice.
I wish to start with a simple version (and I'm working on that already, but I'm stuck on too many things - 95% cos and absolutely new to GUI and 5% cos I'm new to java).
I've checked many tutorials, but they're all simple.
Real questions:
1) Verify. In MVC controller should handle all user actions - is it done by view's method which is something like button.addActionListener(param); anotherButton.addActionListener(paramp; ...?
1b) I've seen all implemented via one (nested) class, which was then checking source or smth - is that ok? There will be a lots of buttons etc.
2) How to implement the data grid, when I need to take actions on click / dbl click?
4) First row is header, the rest should be scroll able - should it be in the grid or outside (its own grid):
4a) How to make sure header's size (width) will be the same as in data (I don't want to set up straight size)
4b) I failed to create anything scrollable so far, but thats my bad I guess. How to ensure header will hold on a place and the rest can be scrolled?
5) How should be "data update" implemented? I've got JPanel from which I remove grid component and then I make new one and add data into it (simple, but perhapss there is another way). One of first enhancements will be sorting - use the same way I used for new content?
Thanks a lot for any answer, I know this is not very specific, but example I've found are too simple.
I plan a lots of enhancements, but thats in the future and I don't mind to rework GUI/Controller several times, at least, I'll practise, but I don't want to finish one part of the code and realise I've got to rewrite half of a controller and 1/4 of a view to make it possible.
Note: I plan to use this at work as my tool (if things go right, I could make 25-50% of my work by few clicks :-)
So I really mean this).
Note#2: I'm not new to programing, but I've never created GUI (which is why I've got GUI with menu bar with 2 items and 3 components and almost done web-iface connections).
Note#:3 dragable data header, tabbed data view - thats the plan for the future :-)
MVC in Swing is examined here; use nested classes for ease in prototyping and creating an mcve for future questions; as the need arises, nested classes can be promoted to separate classes having package-private access.
Use JTable; its flyweight implementation of renderers is good for organizing data by row and column.
Item three does not exist, but "always remember to translate cell coordinates" if you plan to drag columns or sort rows.
Use a JScrollPane to keep the table header stationary.
Update the TableModel, and the listening view will update itself in response.
If you are interested not only from the event/messaging architecture, but also on handling mouse/keyboard input, hovering detection, widgets, temporary menus, form re-sizing with widget alignment, dragging and dropping etc. I can advice you to look at this question and my answer with helpful resources.
I am very new to Vaadin. My requirement is like in my page I need to have 4 input component per row. There would be 4 rows like this. I need a layout which will allow me to define number of columns and keep align it.
There should not be any border like we have in table. Please suggest me any suitable layout and how can I customize that.
Thanks
You are probably looking for a GridLayout, it provides enough flexibility to size your grid 'cells', maintain consistency and set expand ratios for row and columns separately.
The other option for you is to use a CustomComponent and in case you are using Vaadin plugin for eclipse (and I don't have experience with Vaadin on any other IDE) you can use their WYSIWYG editor to translate your requirement to a custom component.
I'm writing an Eclipse plugin for a screen definition editor. The preview page will have multiple tables of different rows/columns definitions, the contents of each cell is effectively a control definition (i.e. Label, TextBox, etc). Some basic requirements of the preview are:
User selection on any cell publishes the control properties to another view.
The cell styling is applied depending upon the control type.
Currently using JFace TableViewers but have the following issues:
1. Only one TableViewer can be registered as a selection provider via the getSite().setSelectionProvider(). How to listen for selection changes on all my tables?
2. TableViewer does not appear to allow for cell styling.
3. Cell selection programatically handling with a TableCursor, but the cell in a previous table is still highlighted when I select another cell in another table.
Are there more suitable layouts to use than TableViewer for my purposes?
Regarding point #2, cell styling, TableViewers do allow for customization of the display of cell data. Take a look here for some ideas on how to get started with that.
You can use this approach for supporting selection in multiple tables with some modification (add listener to each of your table viewers so if one of them is selected it automatically becomes the delegate).
Hi am creating an application in which I am using JTable to listing of file or folder names.
My question is:
How can I find and Search a Particular file or folder in JTable like in Windows.
In windows directory listing when we press any key then we can see that file or folder start with that character is selected and if we again press same key then next file/folder is selected with start with that character.
If you can use 3th party code, I would suggest to take a look at the SwingX project. Their JXTable, JXTree, JXList and some other classes provide an implementation of the Searchable interface, which makes creating a search widget a breeze.
And if that is even too difficult, they provide out-of-the-box a JXFindPanel which provides a UI to search a Searchable
If you can (and you're willing to) use third party UI components, the Open Source JIDE Common Layer offers a few nice components: e.g. you might like FolderChooser which has an automatic find-as-you-type functionality.
Here's the link: JIDE Common Layer. If you click the "RUN IT" button you can see a sample via Java Web Start.
I've used many JIDE components (only the open source ones) in my projects and avoided reinventing the wheel many times.
Hope this might help you.
You want an action happen when a key is typed ?
-> add a keyListener to your table
You want to know which row is valid
-> query your datamodel connected to your jtable
You want a selected row to change ?
-> in the keytyped implementation of your listener change the selection
table.getSelectionModel().setSelectionInterval(1,1);
Since I don't know something about how did you implement your code logics, JTable implemented Sorting and Filtering
but you describtions talking about JTreeTable
I would consider writing a custom TableCellRenderer, responsible for highlighting any matching letters in the String being rendered. When someone updates the search text field the simplest approach is going to then be to repaint the entire JTable to show the updated "match state" of the table cells.
I need to create a JTextField (or any component where I can type something) and it has to offer a list of dynamicaly populated values. When I type a new character, the propositions are updated (Like Ajax does)
One particularity is that the user can only choose a value that was populated. I need that for my users to select an existing city from a database.
What would be the easiest way to make it with Swing ?
Thank you.
You can implements Auto complete ComboBox / JFextField based on standard Java API, there aren't any issues with Focus or Caret nor with performance for largiest Arrays for autocompleted JComboBox and JTextField
I have used the JIDE Common Layer for autocompletion in Java Swing. Take a look at the WebStart demo.
It's free and open source, and if the provided autocompletion options don't quite match what you are trying to do I found it really easy to plug in my own logic.
You can use Swingx.Contains extensions to the Swing GUI toolkit, including new and enhanced components that provide functionality commonly required by rich client applications. Highlights include:
Sorting, filtering, highlighting for tables, trees, and lists
Find/search
Auto-completion
Login/authentication framework
TreeTable component
Collapsible panel component
Date picker component
Tip-of-the-Day component