如何为JavaFX2 TableView
TableColumn
“宽度更改”事件监听器创建?
我想到的是:
tableView.getColumns().addListener(new ListChangeListener() {
public void anyMethod() {
System.out.println("TableView Column Width Have Changed")
}
}
答案 0 :(得分:1)
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);
}
});
}
}
答案 1 :(得分:0)
TableColumn有一个widthProperty(),您可以将自己附加到
答案 2 :(得分:0)
试试这个.....它的工作
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");
}
});