如何为 JavaFX2 TableView
TableColumn
“宽度更改”事件侦听器创建?
我想到了类似的东西:
tableView.getColumns().addListener(new ListChangeListener() {
public void anyMethod() {
System.out.println("TableView Column Width Have Changed")
}
}
试试这个.....它的工作
Column.widthProperty().addListener(new ChangeListener<Number>
() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
System.out.println("change in the widht of address");
}
});
的示例代码WidthProperty()
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* @author reegan
*/
public class TableWidthChange extends Application {
@Override
public void start(Stage primaryStage) {
TableView tableView = new TableView();
TableColumn column1 = new TableColumn("Column1");
TableColumn column2 = new TableColumn("Column2");
TableColumn column3 = new TableColumn("Column3");
changelistener(column1);
changelistener(column2);
changelistener(column3);
tableView.getColumns().addAll(column1,column2,column3);
StackPane root = new StackPane();
root.getChildren().add(tableView);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
public void changelistener(final TableColumn listerColumn) {
listerColumn.widthProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
System.out.print(listerColumn.getText() + " ");
System.out.println(t1);
}
});
}
}
TableColumn 有一个 widthProperty() 你可以附加到