This is my current Display board and I would like to add a tooltip on top of the Items menu. How do I do this since itemNameCol.setTooltip is undefined? My code is below.
TableView<AuctionItem> table = new TableView<AuctionItem>();
table.setEditable(true);
table.setMinSize(500, 510);
TableColumn<AuctionItem, String> itemNameCol = new TableColumn<>("Items");
itemNameCol.setCellValueFactory(
new PropertyValueFactory<AuctionItem, String>("name"));
Related
I'm currently developing an eclipse plugin and in that plugin, there is a form view as a design template. In that form view, I have added a Table and there should have two columns in width ratio of 1:2. And also I want that table to be responsive and dynamically change its column width in order to the formView page width.
The following code segment is the one I'm currently using.
Table table = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.BORDER);
fd = new FormData();
fd.height = 200;
fd.top = new FormAttachment(removeTestCaseButton, 5);
fd.left = new FormAttachment(1);
fd.right = new FormAttachment(99);
table.setLayoutData(fd);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn column1 = new TableColumn(testCaseTable, SWT.CENTER);
column.setText("column One");
TableColumn column2 = new TableColumn(testCaseTable, SWT.CENTER);
column2.setText("column Two");
form.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle area = form.getBody().getClientArea();
int width = area.width;
column1.setWidth(width / 3);
column1.setWidth(width * 2 / 3);
}
});
But here the problem is when I open the FormView it works fine. But my table is inside a Section. Once I expand or collapse the Section the table width is getting increased with appearing the horizontal scrollbar.
I just want a solid solution for this.
This is much easier to do using the JFace TableViewer with the TableColumnLayout and ColumnWeightData, but you will have to rework your code to use JFace style content and label providers for the table.
TableColumnLayout tableLayout = new TableColumnLayout();
// A separate composite containing just the table viewer is required
Composite tableComp = new Composite(parent, SWT.NONE);
tableComp.setLayout(tableLayout);
TableViewer viewer = new TableViewer(tableComp, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
TableViewerColumn col1 = new TableViewerColumn(viewer, SWT.LEAD);
col1.getColumn().setText("Column 1");
col1.setLabelProvider(.... label provider for column 1 ....);
// Weight for column
tableLayout.setColumnData(col1.getColumn(), new ColumnWeightData(60));
TableViewerColumn col2 = new TableViewerColumn(viewer, SWT.LEAD);
col2.getColumn().setText("Column 2");
col2.setLabelProvider(....... label provider for column 2 .....);
// Weight for column
tableLayout.setColumnData(col2.getColumn(), new ColumnWeightData(40));
viewer.getTable().setHeaderVisible(true);
viewer.getTable().setLinesVisible(true);
viewer.setContentProvider(ArrayContentProvider.getInstance());
viewer.setInput(.... input data for the viewer ....);
I have the following Node creator in my Java application:
private Node createWelcomePane() {
HBox hbox_accounts = new HBox();
this.getAccounts();
tableAccounts.setPrefSize(500,500);
final Label label = new Label("Address Book");
label.setFont(new Font("Arial", 20));
tableAccounts.setEditable(false);
TableColumn idCol = new TableColumn("ID");
idCol.setMinWidth(100);
idCol.setCellValueFactory(
new PropertyValueFactory<Account, Integer>("id"));
TableColumn typeCol = new TableColumn("Account Type");
typeCol.setMinWidth(100);
typeCol.setCellValueFactory(
new PropertyValueFactory<Account, String>("type"));
TableColumn balanceCol = new TableColumn("Balance");
balanceCol.setMinWidth(200);
balanceCol.setCellValueFactory(
new PropertyValueFactory<Account, Float>("balance"));
tableAccounts.setItems(accountList);
tableAccounts.getColumns().addAll(idCol, typeCol, balanceCol);
hbox_accounts.getChildren().add(tableAccounts);
hbox_accounts.setAlignment(Pos.CENTER);
return hbox_accounts;
}
Which is fine - it creates table. However, table does not have any data in it (however, I can click on first 4 rows - because I have 4 entires in my array).Any ideas why data is not visible?
I found out that I had to add getters and setters to my Account class.
Case solved!
I want to add rows to a table depending on an ID i get earlier.
I have managed to do it in SWT but I do not know how to do it in javaFx.
Here is the code I wrote for SWT:
int availableDesings = designManagement.getNumberOfDesigns();
ArrayList<Design> designs = designManagement.getDesignArray();
for (int i = 0 ; i< availableDesings ; i++){
TableItem item = new TableItem(table, SWT.NONE);
item.setText (0, String.valueOf(designs.get(i).getId()));
item.setText (1, String.valueOf(designs.get(i).getPart_name()));
}
Can anyone help me translating the code to javaFx?
If you have a TableView in JavaFX and it is assigned to a ObservableList of items :
TableView<String> table = new TableView<>();
ObservableList<String> list = FXCollections.observableArrayList();
table.setItems(list);
Then you can add data to the Table, by adding data to the list :
table.getItems().add("New Item");
or, you can directly add data to the list :
list.add("New Item");
For more, information, check this link :
Adding New Rows
private ObservableList<Design> data = FXCollections.observableArrayList();
.....
....
data.addAll(designManagement.getDesignArray()); //all you items
TableView<Design> table = new TableView<>();
TableColumn<Design, String> column1 = new TableColumn<>();
column1.setCellValueFactory(new PropertyValueFactory<Design, String>("id"));
TableColumn<Design, String> column2 = new TableColumn<>();
column2.setCellValueFactory(new PropertyValueFactory<Design, String>("part_name"));
table.getColumns().add(column1);
table.getColumns().add(column2);
table.setItems(data);
you can actually add row to a tableview in javafx though i haven't tried using it. But i have done it with TableColumn.
This is some code that i have done for my small project
TableView<Person> personTable = new TableView<>();
TableColumn<Person,String> nameColumn=new TableColumn<>("Name");
nameColumn.setMinWidth(200);
nameColumn.setCellValueFactory(new PropertyValueFactory<>("Name"));
TableColumn<Person, Gender> genderColumn=new TableColumn<>("Gender");
genderColumn.setMinWidth(30);
genderColumn.setCellValueFactory(new PropertyValueFactory<>("gender"));
TableColumn<Person,String> mobileNumberColumn=new TableColumn<>("mobileNumber");
mobileNumberColumn.setMinWidth(150);
mobileNumberColumn.setCellValueFactory(new PropertyValueFactory<>("mobileNumber"));
TableColumn<Person, Blood> bloodColumn=new TableColumn<>("Blood Type");
bloodColumn.setMinWidth(30);
bloodColumn.setCellValueFactory(new PropertyValueFactory<Person, Blood>("blood"));
personTable.setItems(getPerson());//setting content retrieved from the database into the table
personTable.getColumns().addAll(nameColumn, genderColumn, mobileNumberColumn,bloodColumn);//adding all columns to table
so what it means is when i say
TableColumn mobileNumberColumn=new TableColumn<>("mobileNumber");
i mean mobileNumberColumn is using the class Person from which a string is assigned to the column. the mobile number in quotes is the name of the table.
mobileNumberColumn.setCellValueFactory(new PropertyValueFactory<>("mobileNumber"));
The above line say that the value of the column is the instance variable mobileNumber of the the class person.But for this to work you should have a getMobileNumber() method in person class. It has to be exactly like that for the tableView to work.
hope this helps
I'm having issues getting libgdxs scrollpane control to work. The code below shows control setup for a simple layout with a label, a List of items inside a scrollpane, and a button. The problem is my scroll pane doesn't show anything other than the vScroll/vScrollKnob ninepatch (that tiny white square)
it just looks like this:
screenshot.
private void setupLayout()
{
String[] listEntries = {"1","2","3","4","5"};
ListStyle listStyle = new ListStyle();
NinePatch example = new NinePatch(new Texture(Gdx.files.internal("data/example.9.png")));
listStyle.selectedPatch = example;
listStyle.font = new BitmapFont();
mList = new List(listEntries,listStyle);
ScrollPaneStyle paneStyle = new ScrollPaneStyle();
paneStyle.vScroll = example;
paneStyle.vScrollKnob = example;
mListScroll = new ScrollPane(mList,paneStyle);
mListScroll.setScrollingDisabled(true, false);
mListScroll.width = 500;
mListScroll.height = 500;
LabelStyle ls = new LabelStyle();
ls.font = new BitmapFont();
ls.fontColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
mLabel = new Label("Label", ls);
TextButtonStyle buttonStyle = new TextButtonStyle();
buttonStyle.font = new BitmapFont();
mButton = new TextButton("Button",buttonStyle);
Table table = new Table();
table.add(mLabel);
table.row();
table.add(mButton);
table.row();
table.add(mListScroll);
mStage.addActor(table);
}
It works as expected if i don't user the scroll pane and add the list directly to the table like this:
Table table = new Table();
table.add(mLabel);
table.row();
table.add(mButton);
table.row();
table.add(mList); //changed mListScroll(scrollpane class) to mList(List class)
mStage.addActor(table);
screenshot
But then it will extend out the bottom of my screen when there are too many items. What am I doing wrong here? Is there another parameter i need to set on the scrollpane?
I believe the issue you are having is how you are adding things to the table. I would suggest the following code instead of how you are doing it:
Table table = new Table();
table.add(mLabel);
table.row();
table.add(mButton);
table.row();
// Changing the table layout size itself.
table.add(mListScroll).size(500, 500);
mStage.addActor(table);
For more a more detailed explanation refer to TableLayout the quick start here shows you more how using tables for laying out objects.
I have different controls placed on a table using TableEditor.
...
TableItem [] items = table.getItems ();
for (int i=0; i<items.length; i++) {
TableEditor editor = new TableEditor (table);
final Text text1 = new Text (table, SWT.NONE);
text1.setText(listSimOnlyComponents.get(i).getName());
text1.setEditable(false);
editor.grabHorizontal = true;
editor.setEditor(text1, items[i], 0);
editor = new TableEditor (table);
final CCombo combo1 = new CCombo (table, SWT.NONE);
combo1.setText("");
Set<String> comps = mapComponentToPort.keySet();
for(String comp:comps)
combo1.add(comp);
editor.grabHorizontal = true;
editor.setEditor(combo1, items[i], 1);
} //end of for
...
When I try to get the text on the table using getItem(i).getText, I get empty string
...
TableItem [] items = table.getItems ();
for(int i=0; i<items.length; i++) {
TableItem item = items[i];
String col0text = items[i].getText(0); //this text is empty
String col1text = items[i].getText(1); //this text is empty
}
...
Why does getText returns empty strings even when I have text appearing on the table?
Instead of using the text property, you might consider using the data property instead.
Benefits:
you can attach the data (e.g. a control or complex data structure) directly to the table item.
the only thing your table item creation need to know from your table cell editor is the object reference to be stored in the data property.
you don't need that event handling stuff (just read the controls data when you really need it).
Create:
TableItem item = new TableItem(table, SWT.None);
TableEditor editor = new TableEditor(table);
Button checkbox = new Button(table, SWT.CHECK);
checkbox.pack();
editor.setEditor(checkbox,item,0);
item.setData("cb",checkbox); // using key enables you to add more pieces of complex data
Read:
for (TableItem item : table) {
Button checkbox = (Button) item.getData("cb");
if (checkbox.getSelection()) { /* ... do whatever you want */ }
}
When the table shows up, the checkbox is visible and can be clicked. Using the setText method fails in case of transparent background controls -> you will see the text of the table items cell below
your control (I tried this).
Anyway it would be much easier if it would be possible to extend the table item class to hide even the data key. But as usual, subclassing is denied.
in the event listeners for the controls I added
item.setText call
...
combo1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent evt) {
String sel = combo2.getText();
item.setText(ComponentPortToConnectCol, sel);
}});
...
This gives me the desired result. Thanks OTisler for the clue
How are you setting up your table? I copied your code to debug it and set up the table as shown below (first for loop)
I tried but couldn't reproduce the problem you're seeing. It might be the way you are adding things to the table.
TableEditor Examples
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
for (int i = 0; i < 3; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] { "" + i, "" + i, "" + i });
}
TableItem [] items = table.getItems();
for (int i=0; i<items.length; i++) {
TableEditor editor = new TableEditor (table);
final Text text1 = new Text (table, SWT.NONE);
text1.setText("TEST");
text1.setEditable(false);
editor.grabHorizontal = true;
editor.setEditor(text1, items[i], 0);
editor = new TableEditor (table);
final CCombo combo1 = new CCombo (table, SWT.NONE);
combo1.setText("");
String[] comps = {"A","B","C"};
for(String comp:comps)
combo1.add(comp);
editor.grabHorizontal = true;
editor.setEditor(combo1, items[i], 1);
} //end of for
TableItem [] items2 = table.getItems ();
for(int i=0; i<items2.length; i++) {
TableItem item = items2[i];
String col0text = items2[i].getText(0); //returns '0' first for loop
}