I have a simple GridPane with 2 columns and 9 rows. I add a TextArea in the 6th row. How can i give this TextArea a Columnspan of 2?
MyFxTextArea textArea = new MyFxTextArea();
textArea.setMaxHeight(200);
textArea.setMaxWidth(600);
page.add(textArea,0,6);
You can specify the column span when you are adding the text area to the page:
page.add(textArea,0,6,2,1);
Related
Text 4 is aligned to Text 3, which is aligned to Text 2, which is aligned to Text 1. Text 1 is autonomously aligned.
PROBLEM: When the app sets Text 3 to "INVISIBLE", Text 4 stays at the same layout position. The only thing that changes is that Text 3 is no longer visible.
How can I make Text 4 inherit the constraints of Text 3, which are:
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/textView2"
The desired result would therefore be that Text 4 moves to the position of Text 3.
Have a look at goneMarginStart. It reads: "When a position constraint target's visibility is View.GONE, you can also indicate a different margin value to be used..."
So, setting the gone-start-margin of textview4 to 0 and aligning the top of textview4 with top of textview3 (instead of bottom) should work.
For textview4:
android:layout_marginStart="8dp"
app:layout_goneMarginStart="0dp"
app:layout_constraintStart_toEndOf="#+id/textView3"
app:layout_constraintTop_toTopOf="#+id/textView3"
In a GridLayout, I have set a row to 'auto' because the content size is dynamic. In particular, I have a pulldown menu in the row. When it opens, the row correctly grows to the height of the pulldown list that appears. BUT, when the pulldown is closed, it is merely a button that should have the same height as the other rows. Unfortunately, the row height is a bit too small and causes the overall layout to look bad.
To fix this, I need to set the minimum height of the 'auto' row. Is this possible? Can I set a minimum height for a GridLayout row that is set to 'auto' ???
You can not set minimum height for a particular grid row, instead you can set minHeight (min-height with CSS) on the Button you are talking about / simply wrap the Button with a ContentView / StackLayout if you like to keep the Button smaller while giving it more space.
There have been a number of changes to the GXT library in version 3.1, and I'm not sure that I am using the correct technique for creating an editable integer column in a Grid. It seems that the required code is overly complex, but perhaps that's just how it is. Is there a better way than the following?
ColumnConfig<M, Integer> column = new ColumnConfig<M, Integer>(valueProvider, width, title);
IntegerPropertyEditor editor = new NumberPropertyEditor.IntegerPropertyEditor();
NumberInputCell<Integer> cell = new NumberInputCell<>(editor);
new IntegerField(cell);
column.setCell(cell);
Note that if the new IntegerField(cell) statement is omitted then the column contains a numeric (integer) cell that contains a down arrow (like a combobox arrow), which seems odd.
My fxml file has the following declaration:
< TableView fx:id="myTable" prefHeight="756.0" prefWidth="472.0" />
then in Java code, I add the columns and then setItems as usual. This works as expected.
The only other code which affects the table is:
myTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
which nicely automatically re-sizes the columns. But I can't figure out how to do the following:
When I add say 1 or 10 items to the table, those appear as expected in the first 1 or 10 rows of the table, but the number of rows in the table are always 21. Rest of the rows are just empty. I want the table to have only 1 row if I set 1 item or 10 rows if I set 10 items. How do I achieve this ?
All the columns are of the same size. I can manually re-size them, but I want columns to auto-fit according to their size. For example if I have 2 columns one with integer from 1-10 and another with text description, they both have equal size. How do I tell it to autofit the column size according the the row contents ?
Thanks for the response!
The table fills up the layout with empty rows. Try hiding them by adding css
.table-row-cell:empty {
-fx-background-color: -fx-background;
}
.table-row-cell:empty .table-cell {
-fx-border-width: 0px;
}
For #2 you can check the length of text in the cells in the cell value factory but I have title problems like that. You can read the data set and figure out what it should be. These are both approximations depending on font size.
Added this, my play cellValueFactory where I tried out some things.
TableColumn<LineItem,String> amountCol = new TableColumn<>("Amount");
amountCol.setPrefWidth(amountCol.getText().length()*20);
amountCol.setCellValueFactory(new Callback<CellDataFeatures<LineItem, String>, ObservableValue<String>>() {
#Override
public ObservableValue<String> call(CellDataFeatures<LineItem, String> p) {
SimpleStringProperty ssp = new SimpleStringProperty(String.format("%.4f", p.getValue().getAmount()));
amountCol.setPrefWidth(Math.max(amountCol.getPrefWidth(), ssp.get().length()*20));
return ssp;
}
});
I have a QTableView inside a layout itself inside a Widget.
How I can set the Widget size after the call of tableView.resizeColumnsToContents() in order to have the same size of the table (and does not need a scrollbar )
Thanks
If I understand properly what you want is to adjust the horizontal size of the container widget to the size of the table contents (which is not necessarily the table size). The following method works for me with a small table of 20 rows and 3 columns:
ask the table model for the total number of columns (it should be returned by your implementation of the columnCount method)
ask the view for the width of every column using the columnWidth method and compute the total width of the columns
finally resize your container widget taking into account the total width of columns, the width of the table vertical header and the autoscroll margin
So the code would look like:
my_table_view.resizeColumnsToContents()
w = 0
for c in range(my_table_model.columnCount()):
w = w + my_table_view.columnWidth(c)
container_widget.resize(w + my_table_view.verticalHeader().width() + my_table_view.autoScrollMargin()*1.5, container_widget.size().height())
As I said, I'm assuming that you want to resize your widget horizontally.