0

I added into my table the option table.setTableMenuButtonVisible(true); in order to show and hide columns.

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();
    }
}

Can I for example show the columns First Name and Last Name by default and to hide Email?

Is there any option for this?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
  • The [obvious thing](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableColumnBase.html#setVisible-boolean-) doesn't work? – James_D Apr 28 '15 at 01:38
  • @James_D I tested `setVisible` into the above code with Java8u60b12. Looks like there is a bug into `setTableMenuButtonVisible(true);` When I remove column from the context menu the menu is completely removed from the combo box list. – Peter Penzov Apr 28 '15 at 07:54
  • Yes, looks like a [bug in 1.8.0_60 ea](https://javafx-jira.kenai.com/browse/RT-40217). It works fine in 1.8.0_40. – James_D Apr 28 '15 at 12:48
  • I found this post: http://stackoverflow.com/questions/27739833/adapt-tableview-menu-button It's exactly what I need. Is there any way to make the same result but without using sun packages from the internal JavaFX API? – Peter Penzov Apr 28 '15 at 14:39

0 Answers0