Javafx 8 仅显示表中的默认列
我在我的表中添加了选项table.setTableMenuButtonVisibletrue;以显示和隐藏列Javafx 8 仅显示表中的默认列,javafx-8,Javafx 8,我在我的表中添加了选项table.setTableMenuButtonVisibletrue;以显示和隐藏列 import javafx.application.Application; import static javafx.application.Application.launch; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scen
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class MainApp extends Application
{
private TableView table = new TableView();
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage stage)
{
Scene scene = new Scene(new Group());
stage.setTitle("Table View Sample");
stage.setWidth(300);
stage.setHeight(500);
final Label label = new Label("Address Book");
label.setFont(new Font("Arial", 20));
table.setEditable(true);
TableColumn firstNameCol = new TableColumn("First Name");
TableColumn lastNameCol = new TableColumn("Last Name");
TableColumn emailCol = new TableColumn("Email");
table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
table.setTableMenuButtonVisible(true);
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
vbox.getChildren().addAll(label, table);
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.show();
}
}
例如,我是否可以默认显示“名”和“姓”列并隐藏电子邮件
有任何选项吗?不起作用?@James_D我用Java8u60b12在上述代码中测试了setVisible。看起来setTableMenuButtonVisibletrue中有一个bug;当我从上下文菜单中删除列时,该菜单将从组合框列表中完全删除。是的,看起来像一个。它在1.8.0_40中运行良好。我发现这篇帖子:它正是我所需要的。是否有任何方法可以产生相同的结果,但不使用来自内部JavaFXAPI的sun包?