How to create column and set name in JavaFx TreeTableView - javafx

how can i create column and set their name from a list of String in JavaFx. Is there a methode like public String getColumnName(int column) and getColumnCountas in swingx in JavaFx?

No, the data model for a JavaFX TreeTableView is managed differently to the way the data model is managed in Swing.
The data model is represented by two properties in the TreeTableView class: root and columns.
root is a TreeItem<T> (where T is the data type represented by each row of the TreeTableView). It has a getChildren() method for child elements in the tree structure, expanded state, etc.
getColumns() returns an ObservableList<TreeTableColumn<T,?>>, which is essentially a list of columns. So the number of columns is determined by the size of this list. TreeTableColumn has a text property which encapsulates the title of the column. So the column names are represented by the text properties of the elements of the list returned by getColumns().
So, to sort of answer your question, given
TreeTableView<T> treeTable ;
(where T is replaced by some actual type), and
List<String> columnNames ;
you can populate the columns of the tree table with
for (String name : columnNames) {
TreeTableColumn<T,?> column = new TreeTableColumn<>(name);
treeTable.getColumns().add(column);
}
or if you prefer a Java 8 style:
columnNames.stream().map(TreeTableColumn::new)
.forEach(treeTable.getColumns()::add);
However, note that you almost certainly need to set a cell value factory on each column, and possibly configure it further in other ways.

Related

how to add QSpinBox to a QTableWidget?

I have a QTableWidget and an object of class product called p.
I wanna add items to this table.
I tried the code below but no use.
void MainWindow:: add_to_basket (product p){
ui->tableWidget->insertRow(1);
QLineEdit *qle=new QLineEdit();
qle->setText(p.get_name());
ui->tableWidget->setCellWidget(1,1,qle);
QLineEdit *qle1=new QLineEdit();
qle1->setText(QString::number(p.get_price()));
ui->tableWidget->setCellWidget(1,2,qle1);
QSpinBox *qsb=new QSpinBox();
qsb->setValue(p.get_count());
ui->tableWidget->setCellWidget(1,3,qsb);
}
what should I do?
QTableWidget should have defined rowCount and columnCount properties. It can be done either via QTableWidget constructor (https://doc.qt.io/qt-5/qtablewidget.html#QTableWidget-1) or via appropriate methods (setRowCounts and setColumnCounts). If it is done already, that's great.
insertRow inserts an empty row into the table at given position. ui->tableWidget->insertRow(1) would insert a new row at position 1 only if you have previously defined rowCount and columnCount (see point 1).
It depends what is your idea here - if you would like to have at least 4 columns (please note that we are counting from 0 and the QSpinBox is attempted to be put into third column) and insert new product always at first row, your code with point 1 fullfilled will be work fine. But, if your idea is to add a new row each time new product is added, you should rather call ui->tableWidget->insertRow(tableWidget->rowCount()) and use that value to address appropriate row.
You may also want to have a look here for example how to setup QTableWidget: https://wiki.qt.io/How_to_Use_QTableWidget

JavaFX Simplest way to get cell data using table index

Is there any simplest way to get cell data of a tableview in javafx using table index values without using cellfactory function.Iam looking simple single line code like this
getValueAt(1,2);//1=column number 2=row number
So i can access the cell data on column=1 and row=2.Thanks in advance
You can get the observable using the TableColumn and use getValue on it:
public static Object getValueAt(TableView table, int column, int row) {
return table.getColumns().get(column).getCellObservableValue(row).getValue();
}
You can also use the following code. when you select a row using mouse
ProcessDetail pd =
(ProcessDetail)tableDefined.getSelectionModel().getSelectedItem();
System.out.println("Value is in this row which is selected"+pd.getStatus());

In Biztalk mapper how to use split array concept

Required suggestion on below part.please any one give solution.
We have mapping from 850 to FlatFile
X12/PO1Loop1/PO1/PO109 and I need to map to field VALUE which is under record Option which is unbounded.
Split PO109 into substrings delimited by '.', foreach subsring after the first, create new Option with value=substring
So in input sample we have value like 147895632qwerqtyuui.789456123321456987
Similarly the field repeats under POLoop1.
So I need to split value based on (.) then pass a value to value field under option record(unbounded).
I tried using below code snippet
public string SplitValues(string strValue)
{
string[] arrValue = strValue.Split(".".ToCharArray());
foreach (string strDisplay in arrValue)
{
return strDisplay;
}
}
But it doesn't works, and I am not really familiar with the String methods and I am not sure if there's an easy way to do this. I have a String which contains couple of values delimited with "." .
So I need to separate values based on delimiter(.) and pass value to field.
How can I do this
As I mentioned, not too clear what is your objective, but I think you want to split a node that has some kind of delimiter into multiple nodes... if so, Try this: https://seroter.wordpress.com/2008/10/07/splitting-delimited-values-in-biztalk-maps/
He is doing exactly that. Given a node with a|b|c|d as value, output multiple nodes, each containing the value after splitted by |, so node1 = a, node2 = b, node3 = c, node4 = d.

Sizing a spark list

I'm using spark Lists and PopupAnchors to build a drop down menu system, but I'm having trouble getting it to size reliably - the list always seems to want to take up 5 itemRenderers worth of space, but some of the menus I need to implement can be 3 or less items long. How can I have the list dynamically size to the number of elements in it, and no larger?
This is a fun one. You need to set the property on the VerticalLayout of the spark list.
Try this snippet:
(yourSparkList.layout as VerticalLayout).requestedRowCount = yourDataProvider.length;
This assumes you've got a list named yourSparkList and a dataprovider called yourDataProvider which is populating the list.
If your lists get long, you should set a MAXIMUM constant like so:
public static const MAXIMUM:int = 5;
if(yourDataProvider.length <= MAXIMUM){
(yourSparkList.layout as VerticalLayout).requestedRowCount = yourDataProvider.length;
}else{
(yourSparkList.layout as VerticalLayout).requestedRowCount = MAXIMUM;
}
BTW, there's also a requestedMaxRowCount and a requestedMinRowCount property.

Flex - sorting a datagrid column by the row's label

I'm creating a table that displays information from a MySQL database, I'm using foreignkeys all over the place to cross-reference data.
Basically I have a datagrid with a column named 'system.' The system is an int that represents the id of an object in another table. I've used lableFunction to cross-reference the two and rename the column. But now sorting doesn't work, I understand that you have to create a custom sorting function. I have tried cross-referencing the two tables again, but that takes ~30sec to sort 1200 rows. Now I'm just clueless as to what I should try next.
Is there any way to access the columns field label inside the sort function?
public function order(a:Object,b:Object):int
{
var v1:String = a.sys;
var v2:String = b.sys;
if ( v1 < v2 ){
trace(-1);
return -1;
}else if ( v1 > v2 ){
trace(1);
return 1;
}else {
trace(0);
return 0;
}
}
One way to handle this is to go through the objects you received and add the label as a property on each of them based on the cross-referenced id. Then you can specify your label property to display in your data grid column instead of using a label function. That way you would get sorting as you'd expect rather than having to create your own sort function.
The way that DataGrids, and other list based classes work is by using itemRenderers. Renderers are only created for the data that is shown on screen. In most cases there is a lot more data in your dataProvider than what is seen on screen.
Trying to sort your data based on something displayed by the dataGrid will most likely not give you the results you want.
But, there is no reason you can't call the same label function on your data objects in the sortFunction.
One way is to use the itemToLabel function of the dataGrid:
var v1:String = dataGrid.itemToLabel(a);
var v2:String = dataGrid.itemToLabel(b);
A second way is to just call the labelFunction explicitly:
var v1:String = labelFunction(a);
var v2:String = = labelFunction(b);
In my experience I have found sorting to be extremely quick, however you're recordset is slightly larger than what I usually load in memory at a single time.

Resources