How to prevent displaying True/False in column when using Image? - objectlistview

I would like to have an image in column for boolean type. To specify column properties, I use OLVColumn attribute and there I specify ImageAspectName.
[OLVColumn("UseK", DisplayIndex = 4, ImageAspectName = "ImageForUseK", CheckBoxes = false, Width = 40)]
public bool UseK
{
get { return useK; }
set
{
if (useK == value) return;
useK = value;
OnPropertyChanged("UseK");
}
}
protected bool useK = true;
public string ImageForUseK()
{
return "success";
}
This works fine and displaying image in column, but also displaying literal "True" next to image.
How can I avoid displaying string value of boolean property, while still using ImageAspectName?

You could set AspectToStringFormat to a space.

Related

Creating Trending line on bar chart

I have a Bar chart on Kentico reporting section. And I know Kentico uses Microsoft Chart Controls. Microsoft Chart controls have the capability of creating a trending line on Bar graph - But I do see any option how I can utilize those on Kentico Reporting.
Is there any option there on reporting tool to get this trending line ?
If there is no option can anybody suggest anything else ?
Using custom module is the last option for me to try. If anybody has any specific suggestion regarding this custom module, please share that, too.
I am using Kentico 7.
Got it working the way Brend suggested however the mean is not coming up
ChartArea area = graph.ChartControl.ChartAreas[chartAreas - 1];
StripLine line = new StripLine();
// Set threshold line so that it is only shown once
line.Interval = 0;
// Set the threshold line to be drawn at the calculated mean of the first series
line.IntervalOffset = graph.ChartControl.DataManipulator.Statistics.Mean(graph.ChartControl.Series[0].Name);
line.BackColor = System.Drawing.Color.DarkGreen;
line.StripWidth = 0.25;
// Set text properties for the threshold line
//line.Text = "Mean";
line.ForeColor = System.Drawing.Color.Black;
// Add strip line to the chart
area.AxisY.StripLines.Add(line);
Also, for other trend line I am using bellow code, again having no luck as it looks like the datapoints are not set at the point where my code runs :
int chartAreas = graph.ChartControl.ChartAreas.Count;
if (chartAreas > 0)
{
graph.ChartControl.Series.Add("TrendLine");
graph.ChartControl.Series["TrendLine"].ChartType = SeriesChartType.Line;
graph.ChartControl.Series["TrendLine"].BorderWidth = 3;
graph.ChartControl.Series["TrendLine"].Color = System.Drawing.Color.Red;
// Line of best fit is linear
string typeRegression = "Linear";//"Exponential";//
// The number of days for Forecasting
string forecasting = "1";
// Show Error as a range chart.
string error = "false";
// Show Forecasting Error as a range chart.
string forecastingError = "false";
// Formula parameters
string parameters = typeRegression + ',' + forecasting + ',' + error + ',' + forecastingError;
graph.ChartControl.Series[0].Sort(PointSortOrder.Ascending, "X");
// Create Forecasting Series.
graph.ChartControl.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, parameters, graph.ChartControl.Series[0], graph.ChartControl.Series["TrendLine"]);
}
The actual issue, I guess, is not having the graph.ChartControl.Series[0] at the place I am running my TrendLine generation code. Any idea how can I get it ?
Report charts are rendered through \CMSModules\Reporting\Controls\ReportGraph.ascx
You can modify the method GetReportGraph and add additional setup to the chart control ucChart based on some condition, e.g. the report name and chart name (you will have to hardcode that)
Note that you will need to modify Kentico code directly, so keep the changes at the lowest possible level, I recommend:
Put the extra setup code to an external class
Call it with just one extra line of code
Add comment to mark that extra line of code as customization
e.g.:
/* YourCompany */
MyChartExtender.ExtendChart(ucChart, ...);
/* YourCompany end */
Make sure you note that change for future upgrades
I've modified the controls before and you can use this code in the GetReportGraph() method just before enabling the subscription.
// apply the trendline
if (TrendValue > 0)
{
int chartAreas = graph.ChartControl.ChartAreas.Count;
if (chartAreas > 0)
{
ChartArea area = graph.ChartControl.ChartAreas[chartAreas - 1];
StripLine line = new StripLine();
line.IntervalOffset = TrendValue;
line.BorderColor = System.Drawing.ColorTranslator.FromHtml(TrendColor);
line.BackColor = System.Drawing.ColorTranslator.FromHtml(TrendColor);
line.StripWidth = TrendLineWidth;
line.ToolTip = TrendToolTip;
line.Text = TrendText;
line.TextLineAlignment = trendLineAlignment;
line.TextOrientation = TextOrientation.Horizontal;
line.TextAlignment = trendTextAlignment;
area.AxisY.StripLines.Add(line);
}
}
Of course you'll have to add the appropriate properties and pass the values through from the rest of the pages/controls using this control.
#region Trending
/// <summary>
/// Value for the single trendline for whole chart
/// </summary>
public int TrendValue
{
get
{
return mTrendValue;
}
set
{
mTrendValue = value;
}
}
/// <summary>
/// Color of the trend line in hex format (i.e. #0000FF)
/// </summary>
public string TrendColor
{
get
{
return mTrendColor;
}
set
{
mTrendColor = value;
}
}
/// <summary>
/// Tool tip of the trend line
/// </summary>
public string TrendToolTip
{
get
{
return mTrendToolTip;
}
set
{
mTrendToolTip = value;
}
}
/// <summary>
/// Text of the trend line
/// </summary>
public string TrendText
{
get
{
return mTrendText;
}
set
{
mTrendText = value;
}
}
/// <summary>
/// Trend line width
/// </summary>
public double TrendLineWidth
{
get
{
return mTrendLineWidth;
}
set
{
mTrendLineWidth = value;
}
}
string mTrendLineAlignment;
public string TrendLineAlignment
{
get
{
return mTrendLineAlignment;
}
set
{
mTrendLineAlignment = value;
}
}
private System.Drawing.StringAlignment trendLineAlignment
{
get
{
switch (TrendLineAlignment)
{
case "center":
return System.Drawing.StringAlignment.Center;
case "near":
return System.Drawing.StringAlignment.Near;
case "far":
return System.Drawing.StringAlignment.Far;
default:
return System.Drawing.StringAlignment.Near;
}
}
}
string mTrendTextAlignment;
public string TrendTextAlignment
{
get
{
return mTrendTextAlignment;
}
set
{
mTrendTextAlignment = value;
}
}
private System.Drawing.StringAlignment trendTextAlignment
{
get
{
switch (TrendTextAlignment)
{
case "center":
return System.Drawing.StringAlignment.Center;
case "near":
return System.Drawing.StringAlignment.Near;
case "far":
return System.Drawing.StringAlignment.Far;
default:
return System.Drawing.StringAlignment.Near;
}
}
}
#endregion

System.FormatException was unhandled

In form load i'm updating Drop Down List Value
ddlFont:
foreach (FontFamily font in System.Drawing.FontFamily.Families)
{
ddlFont.Items.Add(font.Name);
}
ddlFontSize:
for (int i = 8; i < 24; i++)
{
ddlFontSize.Items.Add(i.ToString().Trim());
}
ddlFontStyle:
ddlFontStyle.Items.Add(System.Drawing.FontStyle.Bold.ToString());
ddlFontStyle.Items.Add(System.Drawing.FontStyle.Italic.ToString());
ddlFontStyle.Items.Add(System.Drawing.FontStyle.Regular.ToString());
ddlFontColor:
ddlColor.Items.Add(System.Drawing.Color.Black.Name.ToString());
ddlColor.Items.Add(System.Drawing.Color.Blue.Name.ToString());
ddlColor.Items.Add(System.Drawing.Color.Green.Name.ToString());
ddlColor.Items.Add(System.Drawing.Color.Red.Name.ToString());
ddlColor.Items.Add(System.Drawing.Color.White.Name.ToString());
ddlColor.Items.Add(System.Drawing.Color.Yellow.Name.ToString());
If user change the Font, size, style, color then i must change RichTextBox control text font, size, style, color.
I call the "FontFormation" method from SelectedIndexChanged event of Drop Down List controls which is having Font Name ddl, Font Style ddl, Font Size ddl.
private void ddlFont_SelectedIndexChanged(object sender, EventArgs e)
{
FontFormation();
}
In my code first two conditions are executing without error but last one alone showing "Input string was not in a correct format" error at ddlFont.Text.
public void FontFormation()
{
if (FontStyle.Bold.ToString() == ddlFontStyle.Text)
{
rchtxtMainBody.Font = new System.Drawing.Font(ddlFont.Text, Convert.ToUInt32(ddlFontSize.Text), FontStyle.Bold);
}
else if(FontStyle.Italic.ToString() == ddlFontStyle.Text)
{
rchtxtMainBody.Font = new System.Drawing.Font(ddlFont.Text, Convert.ToUInt32(ddlFontSize.Text), FontStyle.Italic);
}
else if (FontStyle.Regular.ToString() == ddlFontStyle.Text)
{
rchtxtMainBody.Font = new System.Drawing.Font(ddlFont.Text, Convert.ToUInt32(ddlFontSize.Text), FontStyle.Regular);
}
}
If i remove my last else if condition i.e FontStyle.Regular.ToString() == ddlFontStyle.Text then code is getting executed without any error.
The problem lies in your ddlFontSize.Text. The exception occurs when it cannot convert in to UInt32. Please debug your code and make sure that ddlFontSize.Text doesn't have "px" or "pt" with and and its only a number in string format.

ExpandableListView - onItemLongClick - getPackedPositionChild always returns 0

ExpandableListView.getPackedPositionChild(id) below is always returning 0. The group position is correct, but I can't get the correct child position. What's wrong with the code below?
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
int groupPosition = ExpandableListView.getPackedPositionGroup(id);
int childPosition = ExpandableListView.getPackedPositionChild(id);
// do something
return true;
}
return false;
}
A bit of addition code is needed. You must first convert the input Integer-based flat List position to a Long-based Packed Position. Tested code follows:
#Override
public boolean onItemLongClick( AdapterView<?> parent,
View view,
int position,
long id) {
// convert the input flat list position to a packed position
long packedPosition = m_expandableListView.getExpandableListPosition(position);
int itemType = ExpandableListView.getPackedPositionType(packedPosition);
int groupPosition = ExpandableListView.getPackedPositionGroup(packedPosition);
int childPosition = ExpandableListView.getPackedPositionChild(packedPosition);
// GROUP-item clicked
if (itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
// ...
onGroupLongClick(groupPosition);
}
// CHILD-item clicked
else if (itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
// ...
onChildLongClick(groupPosition, childPosition);
}
// return "true" to consume event - "false" to allow default processing
return false;
}

searching in List<>

i want to find value in List<> but i am not getting the integer value. Here is my code from that i want to find the value in the List
private void txtnapsaserach_TextChanged(object sender, EventArgs e)
{
try
{
//decimal find = decimal.Parse(txtnapsaserach.Text);
if (decimal.Parse(txtnapsaserach.Text) > 0)
{
List<NapsaTable> _napsatabs = this.napsaTableBindingSource.List as List<NapsaTable>;
this.napsaTableBindingSource.DataSource =
_napsatabs.Where(p =>p.NapsaRate.Equals(txtnapsaserach.Text)).ToList();
}
}
catch (Exception Ex)
{
}
}
any solution for me . Because this works for me when i try to find string value.
private void txtnapsaserach_TextChanged(object sender, EventArgs e)
{
float value;
if (!float.TryParse(txtnapsaserach.Text, out value))
return; // return if text cannot be parsed as float number
if (value > 0)
{
var napsatabs = napsaTableBindingSource.List as List<NapsaTable>;
napsaTableBindingSource.DataSource =
napsatabs.Where(p =>p.NapsaRate == value).ToList();
}
}
try this
i want to find value in List<> but i am not getting the integer value.
Your p.NapsaRate is either integer type or floating point number, (probably decimal) Convert your txtnapsaserach.Text to decimal value and then compare it in where clause.
decimal rate = 0;
if(!decimal.TryParse(txtnapsaserach.Text), out rate)
{
//Invalid number in textbox
}
this.napsaTableBindingSource.DataSource =
_napsatabs.Where(p =>p.NapsaRate == rate)).ToList();
if p.NapsaRate is of type double or float you can parse them accordingly using Double.TryParse or Double.Parse etc
The reason you are not getting any error is that you are using object.Equals method for comparing decimal value with string. You should always use == for equality comparison of value types.

javafx column in tableview auto fit size

afaik The TableView in javafx have 2 column resize policies: CONSTRAINED_RESIZE_POLICY and UNCONSTRAINED_RESIZE_POLICY, but I want columns is resized to fit the content of theirs cells
I think it's a simple problem in other platform (like datagridview in C#) but can not resolve
After 3 years I come back to this problem again, some suggestions are calculating the size of text of data in each cell (it's complicated depending on font size, font family, padding...)
But I realize that when I click on the divider on table header, it's resized fit to content as I want. So I dig into JavaFX source code I finally found resizeColumnToFitContent method in TableViewSkin, but it is protected method, we can resolve by reflection:
import com.sun.javafx.scene.control.skin.TableViewSkin;
import javafx.scene.control.Skin;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class GUIUtils {
private static Method columnToFitMethod;
static {
try {
columnToFitMethod = TableViewSkin.class.getDeclaredMethod("resizeColumnToFitContent", TableColumn.class, int.class);
columnToFitMethod.setAccessible(true);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
public static void autoFitTable(TableView tableView) {
tableView.getItems().addListener(new ListChangeListener<Object>() {
#Override
public void onChanged(Change<?> c) {
for (Object column : tableView.getColumns()) {
try {
columnToFitMethod.invoke(tableView.getSkin(), column, -1);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
});
}
}
Note that we call "tableView.getItems()" so we have to call this function after setItems()
After testing the previous solutions I finally found one that worked for me.
So here is mine (call the method after inserting the data into table):
public static void autoResizeColumns( TableView<?> table )
{
//Set the right policy
table.setColumnResizePolicy( TableView.UNCONSTRAINED_RESIZE_POLICY);
table.getColumns().stream().forEach( (column) ->
{
//Minimal width = columnheader
Text t = new Text( column.getText() );
double max = t.getLayoutBounds().getWidth();
for ( int i = 0; i < table.getItems().size(); i++ )
{
//cell must not be empty
if ( column.getCellData( i ) != null )
{
t = new Text( column.getCellData( i ).toString() );
double calcwidth = t.getLayoutBounds().getWidth();
//remember new max-width
if ( calcwidth > max )
{
max = calcwidth;
}
}
}
//set the new max-widht with some extra space
column.setPrefWidth( max + 10.0d );
} );
}
I think just by overriding a call back function that returns true will solve your problem it will disable the re-sizing of columns and all columns will be re-sized to fit the content of their cells.
Example:
TableView<String[]> table = new TableView<>();
table.setColumnResizePolicy(new Callback<TableView.ResizeFeatures, Boolean>() {
#Override
public Boolean call(ResizeFeatures p) {
return true;
}
});
If you want that only one column fills the remaining width of a table, I have found a pretty straight forward solution, which is short and does not require the hacky reflection solution described above:
DoubleBinding usedWidth = columnA.widthProperty().add(columnB.widthProperty()).add(columnC.widthProperty());
fillingColumn.prefWidthProperty().bind(tableView.widthProperty().subtract(usedWidth));
Or to make it short:
// automatically adjust width of columns depending on their content
configAttributeTreeTable.setColumnResizePolicy((param) -> true );
I have used the other solutions on this question, and it works pretty good. However, the downside of this is when the width of the TableView is greater than the required width of the TableColumns together. I have created a hack to solve this problem, and it works OK:
orderOverview.setColumnResizePolicy((param) -> true );
Platform.runLater(() -> FXUtils.customResize(orderOverview));
where FXUtils.customResize() is created as follows:
public static void customResize(TableView<?> view) {
AtomicDouble width = new AtomicDouble();
view.getColumns().forEach(col -> {
width.addAndGet(col.getWidth());
});
double tableWidth = view.getWidth();
if (tableWidth > width.get()) {
TableColumn<?, ?> col = view.getColumns().get(view.getColumns().size()-1);
col.setPrefWidth(col.getWidth()+(tableWidth-width.get()));
}
}
I hope this could be helpful for other people as well!
This is the way I found :
tableview.setColumnResizePolicy( TableView.CONSTRAINED_RESIZE_POLICY );
idCol.setMaxWidth( 1f * Integer.MAX_VALUE * 50 ); // 50% width
nameCol.setMaxWidth( 1f * Integer.MAX_VALUE * 30 ); // 30% width
ageCol.setMaxWidth( 1f * Integer.MAX_VALUE * 20 ); // 20% width
This code autoresizes all column widths in relational proportions to the table width,
while it can fix the first column width to a given value when table width is lower than x
// To generalize the columns width proportions in relation to the table width,
// you do not need to put pixel related values, you can use small float numbers if you wish,
// because it's the relative proportion of each columns width what matters here:
final float[] widths = { 1.2f, 2f, 0.8f };// define the relational width of each column
// whether the first column should be fixed
final boolean fixFirstColumm = true;
// fix the first column width when table width is lower than:
final float fixOnTableWidth = 360; //pixels
// calulates sum of widths
float sum = 0;
for (double i : widths) {
sum += i;
}
// calculates the fraction of the first column proportion in relation to the sum of all column proportions
float firstColumnProportion = widths[0] / sum;
// calculate the fitting fix width for the first column, you can change it by your needs, but it jumps to this width
final float firstColumnFixSize = fixOnTableWidth * firstColumnProportion;
// set the width to the columns
for (int i = 0; i < widths.length; i++) {
table.getColumns().get(i).prefWidthProperty().bind(table.widthProperty().multiply((widths[i] / sum)));
// ---------The exact width-------------^-------------^
if (fixFirstColumm)
if (i == 0) {
table.widthProperty().addListener(new ChangeListener<Number>() {
#Override
public void changed(ObservableValue<? extends Number> arg0, Number oldTableWidth, Number newTableWidth) {
if (newTableWidth.intValue() <= fixOnTableWidth) {
// before you can set new value to column width property, need to unbind the autoresize binding
table.getColumns().get(0).prefWidthProperty().unbind();
table.getColumns().get(0).prefWidthProperty().setValue(firstColumnFixSize);
} else if (!table.getColumns().get(0).prefWidthProperty().isBound()) {
// than readd the autoresize binding if condition table.width > x
table.getColumns().get(0).prefWidthProperty()
.bind(table.widthProperty().multiply(firstColumnProportion));
}
}
});
}
}
advice to put the code in an separated TableAutoresizeModel class, there you can handle further calculations, for example on hiding columns add listener...
#HarleyDavidson 's answer in kotlin
val String.fxWidth: Double
get() = Text(this).layoutBounds.width
// call the method after inserting the data into table
fun <T> TableView<T>.autoResizeColumns() {
columnResizePolicy = TableView.UNCONSTRAINED_RESIZE_POLICY
columns.forEach { column ->
column.setPrefWidth(
(((0 until items.size).mapNotNull {
column.getCellData(it)
}.map {
it.toString().fxWidth
}.toMutableList() + listOf(
column.text.fxWidth
)).maxOrNull() ?: 0.0) + 10.0
)
}
}
This will set the minimum width of columns based on the font and the text, so that the column names wont be cropped.
public static void setDataTableMinColumnWidth(TableView<?> dataTable)
{
for (Node columnHeader : dataTable.lookupAll(".column-header"))
{
var columnString = columnHeader.getId();
if (columnString != null)
{
for (Node columnHeaderLabel : columnHeader.lookupAll(".label"))
{
var tableColumn = dataTable.getColumns()
.stream()
.filter(x -> x.getId()
.equals(columnString))
.findFirst();
if (columnHeaderLabel instanceof Label && tableColumn.isPresent())
{
var label = (Label) columnHeaderLabel;
/* calc text width based on font */
var theText = new Text(label.getText());
theText.setFont(label.getFont());
var width = theText.getBoundsInLocal()
.getWidth();
/*
* add 10px because of paddings/margins for the button
*/
tableColumn.get()
.setMinWidth(width + 10);
}
}
}
}
}
How to use:
dataTable.needsLayoutProperty()
.addListener((obs, o, n) -> setDataTableMinColumnWidth(dataTable));
For the Columns, the id property needs to be set first:
TableColumn<BundImportTask, String> columnTask = new TableColumn<>("My Column");
columnTask.setId("MyColumnId");
columnTask.setCellValueFactory(data -> new SimpleStringProperty(data.getValue()
.fileName()));
I implemented a solution that it's fairly more complicated than the ones that I found here, but that allows a specific column to be resized by double clicking on the header, while still letting the user resize columns manually.
This is achieved by listening to click events on the header of the table (TableHeaderRow). When a double click occurs, the specific column header is found by matching the mouse event X and Y.
Note: to make this work it's necessary that each column has an ID set.
// when skin is loaded (hence css), setup click listener on header to make column fit to content max width on double click
tableView.skinProperty().addListener((a, b, newSkin) -> {
TableHeaderRow headerRow = (TableHeaderRow) tableView.lookup("TableHeaderRow");
NestedTableColumnHeader headers = (NestedTableColumnHeader) (headerRow.getChildren().get(1));
headerRow.setOnMouseClicked(evt -> {
if (evt.getClickCount() != 2 || evt.getButton() != MouseButton.PRIMARY) return;
// find the header column that contains the click
for (TableColumnHeader header : headers.getColumnHeaders()) {
if (header.contains(header.parentToLocal(evt.getX(), evt.getY()))) {
fitColumnWidthToContent(header.getId());
}
}
evt.consume();
});
});
The method that takes care of the resizing is the following:
private void fitColumnWidthToContent (String colId) {
// find column matching id
TableColumn column = null;
for (TableColumn tempCol : tableView.getColumns()) {
if (tempCol.getId().equals(colId)) {
column = tempCol;
break;
}
}
if (column == null) {
throw new IllegalStateException("Column ID doesn't match any actual column");
}
// set default width to column header width
Text text = new Text(column.getText());
double max = text.getLayoutBounds().getWidth();
for (int i = 0; i < tableView.getItems().size(); i++ ) {
if (column.getCellData(i) == null) continue;
text = new Text(column.getCellData(i).toString());
double textWidth = text.getLayoutBounds().getWidth();
if (textWidth > max) {
max = textWidth;
}
}
column.setPrefWidth(max + 12);
}
I hope this can be useful to anyone.
In order to allow also manual resizing, it's necessary to add a bit more code on table initalization:
// listen to width changes in columns and set to pref width (otherwise if for example width changes because of
// user resizing the column, applying the old pref width won't work because it stayed the same)
for (TableColumn col : tableView.getColumns()) {
col.widthProperty().addListener((obs, oldVal, newVal) -> {
col.setPrefWidth(newVal.doubleValue());
});
}
I have implemented a solution for TreeTableView. It is still in evolution but it manifests now promising results. Hereafter a description of the solution.
In the control skin class, I added to the control children the TreeTableView and an invisible VBox. A cell factory provide derived cells to the target TreeTableColumn. The derived cells wrap a Label node which is added or removed to the invisible VBox according to the empty property, and which its prefWidth is set according to the cell width. The cells make use of:
getProperties().put(Properties.DEFER_TO_PARENT_PREF_WIDTH, Boolean.TRUE)
I override the cell's computePrefWidth() method as follow:
#Override
protected double computePrefWidth(double height) {
return Double.max(_box.prefWidth(-1.0), super.computePrefWidth(height) + 24.0);
}
The Vbox width property is bind to the TreeTableColumn's prefWidth. This is required to resize as well the header of the column.
Is worth to note, that at the time being, to simplify the development of a solution, this approach works well with built in sort, order, and resize feature disabled. Ie.
_nameColumn = new TreeTableColumn<>("Name");
_nameColumn.setResizable(false);
_nameColumn.setReorderable(false);
_nameColumn.setSortable(false);
Happy coding
After long research. Best Solution is..
tblPlan.setColumnResizePolicy((param) -> true );
Platform.runLater(() -> customResize(tblPlan));
"Custom Resize"
public void customResize(TableView<?> view) {
AtomicLong width = new AtomicLong();
view.getColumns().forEach(col -> {
width.addAndGet((long) col.getWidth());
});
double tableWidth = view.getWidth();
if (tableWidth > width.get()) {
view.getColumns().forEach(col -> {
col.setPrefWidth(col.getWidth()+((tableWidth-width.get())/view.getColumns().size()));
});
}
}
<TableView fx:id="datalist" layoutX="30.0" layoutY="65.0" prefHeight="400.0" AnchorPane.bottomAnchor="100.0" AnchorPane.leftAnchor="30.0" AnchorPane.rightAnchor="30.0" AnchorPane.topAnchor="100.0">
<columns>
<TableColumn fx:id="number" minWidth="-1.0" prefWidth="-1.0" style="width: auto;" text="number" />
<TableColumn fx:id="id" minWidth="-1.0" prefWidth="-1.0" text="id" />
<TableColumn fx:id="name" minWidth="-1.0" prefWidth="-1.0" text="name" />
<TableColumn fx:id="action" minWidth="-1.0" prefWidth="-1.0" text="todo" />
</columns>
**<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>**
</TableView>

Resources