logo
down
shadow

JavaFX8- Anchoring TableView column's ContextMenu immediately below the the column's header?


JavaFX8- Anchoring TableView column's ContextMenu immediately below the the column's header?

By : Amani Almo
Date : November 17 2020, 11:55 AM
I wish did fix the issue. Unfortunately for my solution I had to dig deep into the TableViews Skin.
First we have to register for the TableViews skin, so we get notified as soon as it has been set up:
code :
tableView.skinProperty().addListener((w, o, n) -> {
    if (n instanceof TableViewSkin) {
        TableViewSkin<?> skin = (TableViewSkin<?>) n;
            checkChangeContextMenu(skin, column);
    }
});
private static void checkChangeContextMenu(TableViewSkin<?> skin, TableColumn<?, ?> column) {
    NestedTableColumnHeader header = skin.getTableHeaderRow()
            .getRootHeader();
    header.getColumnHeaders().addListener((Observable obs) -> changeContextMenu(header,column));
    changeContextMenu(header, column);
}

private static void changeContextMenu(NestedTableColumnHeader header, TableColumn<?, ?> column) {
    TableColumnHeader headerSkin = scan(column, header);
    if (headerSkin != null) {
        headerSkin.setOnContextMenuRequested(ev -> {
            ContextMenu cMenu = column.getContextMenu();
            if (cMenu != null) {
                cMenu.show(headerSkin, Side.BOTTOM, 5, 5);
            }
            ev.consume();
        });
    }
}

private static TableColumnHeader scan(TableColumn<?, ?> search,
        TableColumnHeader header) {
    // firstly test that the parent isn't what we are looking for
    if (search.equals(header.getTableColumn())) {
        return header;
    }

    if (header instanceof NestedTableColumnHeader) {
        NestedTableColumnHeader parent = (NestedTableColumnHeader) header;
        for (int i = 0; i < parent.getColumnHeaders().size(); i++) {
            TableColumnHeader result = scan(search, parent
                    .getColumnHeaders().get(i));
            if (result != null) {
                return result;
            }
        }
    }

    return null;
}


Share : facebook icon twitter icon
TableView: one header with multiple columns

TableView: one header with multiple columns


By : Rajeev Singh
Date : March 29 2020, 07:55 AM
will help you You can achieve this by explicitly setting the height of the sub-column to zero through css:
code :
column.setStyle("-fx-pref-height: 0;")
Q: JavaFX8 resize gridpane columns dynamically

Q: JavaFX8 resize gridpane columns dynamically


By : Brian Vega Rodriguez
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I think for just a two by two grid the easiest solution would be to use three nested Split panes. A major vertical one which is then again subdivided by two minor horizontal ones (or vize versa). You just have to be carefull to synchronize the two minor ones so that they move in parallel.
How do I make QML TableView have two columns with a single header?

How do I make QML TableView have two columns with a single header?


By : Kassandra Chiran
Date : March 29 2020, 07:55 AM
This might help you Each column of TableView is bound to a model item. , Here some simple example:
code :
import QtQuick 2.7
import QtQuick.Window 2.0
import QtQuick.Controls 1.4


Window
{
    width: 600
    height: 500
    visible: true

    ListModel {
        id: myModel
        ListElement {
            column1: "A1"
            column2: "A2"
            column3: "A3"
        }
        ListElement {
            column1: "B1"
            column2: "B2"
            column3: "B3"
        }
        ListElement {
            column1: "C1"
            column2: "C2"
            column3: "C3"
        }
    }

    TableView {
        id: myTable
        anchors.fill: parent
        anchors.margins: 5
        TableViewColumn {
            role: "column1"
            title: "Column1"
            width: myTable.width / 3
            horizontalAlignment: Text.AlignHCenter
        }
        TableViewColumn {
            role: "column2"
            title: "Column2"
            width: myTable.width / 3
            horizontalAlignment: Text.AlignHCenter
        }
        TableViewColumn {
            role: "column3"
            title: "Column3"
            width: myTable.width / 3
            horizontalAlignment: Text.AlignHCenter
        }
        model: myModel
        itemDelegate: Item {
            Row {
                id: row
                anchors.fill: parent
                Text {
                    width: row.width/2
                    text: styleData.value
                    horizontalAlignment: Text.AlignHCenter
                }
                Text {
                    width: row.width/2
                    text: "drop here"
                    color: "red"
                    horizontalAlignment: Text.AlignHCenter
                }
            }
        }
    }
}
Save and Restore state of a TableView (which columns are hidden, width of columns) in JavaFX

Save and Restore state of a TableView (which columns are hidden, width of columns) in JavaFX


By : Jayakrishna Prince
Date : March 29 2020, 07:55 AM
With these it helps First thing you are going to need to do is choose your storage method I recommend either json or xml both have their benefits and have extensive support. Next your going to figure out what values you are going to be storing
All of the columns All the columns widths If the column is visible
code :
{
    name : {
        width:100,
        showing:false
    },
    id : {
        width:50,
        showing:false
    },
    etc.
}
<properties>
    <name>
        <width>100</width>
        <showing>false</showing>
    </name>
    <id>
        <width>50</width>
        <showing>true</showing>
    </id>
    etc.
</properties>
       public void changelistener(final TableColumn listerColumn) {
        listerColumn.widthProperty().addListener(new ChangeListener<Number>() {

            @Override
            public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
                propertyStore.storeWidth(listerColumn.getText(),t1);//when the values are stored
            }
        });
    }
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        public void handle(WindowEvent we) {
           for(int i = 0; i<tv.getColumns().size();i++)
           {
               TableColumn x = (TableColumn) tv.getColumns().get(i);
               propertyStore.storeWidth(x.getText(),x.getWidth());
               propertyStore.storeVisible(x.getText(),x.isVisible());
               //other option 
               propertyStore.storeWidth(x.getId(),x.getWidth());
               propertyStore.storeVisible(x.getId(),x.isVisible());
           }
        }
    });
TableColumn example = new TableColumn("example");
example.setId("ExampleID");
System.out.println(example.getId());//will print ExampleId
Hover over header of a tableView columns

Hover over header of a tableView columns


By : user2969301
Date : March 29 2020, 07:55 AM
this one helps. TableView has a headerDelegate property that contains mouse information:
code :
headerDelegate: Text {
    color: styleData.containsMouse ? "red" : "black"
    text: styleData.value
    // ...
}
headerDelegate: Rectangle {
    height: 20
    implicitWidth: headerText.paintedWidth
    border.color: "black"
    // ...

    Text {
        id: headerText
        color: styleData.containsMouse ? "red" : "black"
        text: styleData.value
        anchors.fill: parent
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
    }
}
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org