check/uncheck all checkboxes using another single checkbox using vaadin [duplicate] - java

Ia m new to vVadin. I created one project with grid with two columns but i want to add one Textfield column and one checkbox column and check all checkboxes when click on header checkbox.
List<Person> people = Arrays.asList(
new Person("Nicolaus Copernicus", 15),
new Person("Galileo Galilei", 15),
new Person("Johannes Kepler", 15));
TextField txt =new TextField();
CheckBox chk=new CheckBox();
// Create a grid bound to the list
Grid<Person> grid = new Grid<>();
grid.setItems(people);
grid.addColumn(Person::getName).setCaption("Name");
grid.addColumn(Person::getAge).setCaption("Year of birth");
grid.addColumn(Person-> new TextField());
layout.addComponents(grid);
setParent(layout);
can anyone suggest me.how to add those two columns

Selection via check boxes works with the multi selection mode, see docs. On the same page you can read about ComponentRenderer which allows to put any component in a column. Note that this feature is available since Vaadin 8.1. released few days ago.

Related

Java Swing want to keep Radio button selection after Restart

Friends
I am a beginner and trying to develop a system level java swing software.
I have 2 JRadio buttons viz A & B in a RadioButton group bg.
I want to keep the radio button selection after restart or until further selection.
Searched for this long in net but getting code for PHP,HTML etc.
Somebody please help me.
rdbtA = new JRadioButton("A");
contentPane.add(rdbtA);
rdbtB = new JRadioButton("B");
contentPane.add(rdbtB);
ButtonGroup bg = new ButtonGroup();
bg.add(A);
bg.add(B);
When you start your application all the graphic components ar re-created, so you have to save the selection in some way when you close your program or when the selection changes (the easiest is to save your choice in a file) and restore it when the software is started (after the buttons creation).
Let me explain this in code:
rdbtA = new JRadioButton("A");
contentPane.add(rdbtA);
rdbtB = new JRadioButton("B");
contentPane.add(rdbtB);
/*
1. If exists a save-file, open it (else, ignore 2. and 3.)
2. read the value of previous A and previous B
3. Set these values to rdbtA and rdbtB
*/
//Rest of the code

Vaadin 8 grid editor doesn't work correctly

Vaadin 8 editor of grid doesn't work correctly when I double click on cell that I can edit.
I use the simple code for create grid and add for one column editor component.
VerticalLayout content = new VerticalLayout();
content.setMargin(false);
content.setSpacing(false);
content.setSizeFull();
setContent(content);
Grid<OrderModel> grid = new Grid(OrderModel.class);
grid.setItems(generate());
grid.setSizeFull();
grid.getEditor().setEnabled(true);
grid.getColumn("planningStatus").setEditorComponent(getCombobox());
Next I run app and start to scroll grid till column "planningStatus".
How it works:
So. What should I do or how I should fix it for correct open editor in grid?
Could your problem be related to issue reported here: https://github.com/vaadin/framework/issues/7746 ?
There exists now also add-on which fixes couple of known Editor cell sizing issues:

group design in eclipse 4 RCP

I want to add an image and a label in a group on a composite by using eclipse 4 RCP. Example image is like below. How can I do this?
My example code is below:
Group group_incom = new Group(dynamicDataComp, SWT.NONE);
group_incom.setLayout(new GridLayout(2,true));
group_incom.setText("Incom. Msg.");
Label lbl_incomMsg = toolkit.createLabel(group_incom, "# of Incoming Messages : ", SWT.NONE);
Image img = new Image(lbl_incomMsg.getDisplay(), "<path>");
lbl_incomMsg.setImage(img);
lbl_incomMsg.setLocation(15, 15);
lbl_incomMsg.pack();
The problem is, I can see the image but I can not see the label text.
Label can display text or an image, it won't display both. So either use two Label controls one for the image and one for the text or use CLabel which can display both.

How to refresh a JTable on JScrollPane

as many other persons, I want my JTable being actualized after adding rows.
Here you can see the fragments of my code.
ArrayList<> foundR = new ArrayList<FoundResult>();
JTable resultsTable = new JTable();
AbstractTableModel resultsModel = new FoundResultTableModel(foundR);//<- model which contains FoundResults as rows
JScrollPane scroller = new JScrollPane();
resultsTable.setModel(resultsModel);
scroller.add(resultsTable);
this.add(scroller, BorderLayout.CENTER);// a big panel which contains scroller and other components
Then a add ActionListener that uses following method:
foundR.clear();
foundR.addAll( ...);//<- so the foundR ArrayList is refreshed
resultsModel.fireTableDataChanged();
resultsModel.fireTableStructureChanged();
rowCount of results Model shows that the model is refreshed (the number of rows differes from the previeous variant), but the table still doesn't appear. I tried to insert resultsTable.repaint() but it also dind't help.
UDP(NB) I discovered, that the problem is concentrated in this scroller Panel.
If I add the table directly to the big panel it is refreshed (but I cannot see all the results, since I cannot scroll down)
this.add(resultsTable, BorderLayout.CENTER);
If I use a scroller, nothing is shown. Do you know why?
Just recreate the model and set it to your table.
foundR.clear();
foundR.addAll( ...);//<- so the foundR ArrayList is refreshed
AbstractTableModel resultsModel = new FoundResultTableModel(foundR);
resultsTable.setModel(resultsModel);
Add this to your code,
resultsTable.revalidate();
Since your model has been changed but the change in model should be notified to the table also.

Tripleplay Button: Dynamic text with proper alignment on an Image Button (say the text justified , centre)

I am creating a window with two image buttons (using TriplePlay in my playN game).
Now I need dynamic text on these buttons. But when I add buttons with images (setIcon), I am not able to add Text on it same time. Please check the following code block I use now.
Interface iface = new Interface(null);
pointer().setListener(iface.plistener);
Styles buttonStyles = Styles.none().add(Style.BACKGROUND.is(new NullBackground())).
addSelected(Style.BACKGROUND.is(Background.solid(0xFFCCCCCC)));
Stylesheet rootSheet = Stylesheet.builder().add(Button.class, buttonStyles).create();
Root buttonroot = iface.createRoot(AxisLayout.horizontal().gap(150), rootSheet);
buttonroot.setSize(width_needed, height_needed);
buttonroot.addStyles(Styles.make(Style.BACKGROUND.is(new NullBackground())));
graphics().rootLayer().add(buttonroot.layer);
Button you = new Button().setIcon(buttonImage);
Button friend = new Button().setIcon(buttonImage);
buttonroot.add(you).add(friend);
buttonroot.layer.setTranslation(x_needed, y_needed);
Root nameroot = iface.createRoot(AxisLayout.horizontal().gap(300), rootSheet);
nameroot.setSize(width_needed, height_needed);
nameroot.addStyles(Styles.make(Style.BACKGROUND.is(new NullBackground())));
graphics().rootLayer().add(nameroot.layer);
name = new Label("YOU");// we need the dynamic string variable instead
friendName = new Label("FRIEND"); // we need the dynamic string variable instead
nameroot.add(name).add(friendName);
nameroot.layer.setTranslation(x_needed, y_needed);
here I have tried making a root then add button with images to it then making another root and add labels on it so that it will be show like text on the image buttons. But I know this is a bad way of doing it, and the alignment will not be according to what needed as it a dynamic text. Is there anyway to add a button, with image and a label on it?
Thanks in anticipation
Creating a button with text and an icon is trivial:
Button button = new Button("Text").setIcon(iconImage);
You can then change the text on the button any time you like, like so:
button.text.update("New Text");
If you want a button with a background image with text rendered over the background, then do the following:
Button button = new Button("Text").
addStyles(Background.is(Background.image(bgImage)));
Note that you will need the latest TriplePlay code (from Github) to use the ImageBackground. The latest code also supports Flash-style "scale9" backgrounds:
Button button = new Button("Text").
addStyles(Background.is(Background.scale9(bgImage)));

Categories