第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

JavaFX:使垂直 ScrollBar 適合 TableView 中的父節(jié)點(diǎn)

JavaFX:使垂直 ScrollBar 適合 TableView 中的父節(jié)點(diǎn)

郎朗坤 2022-08-03 12:44:26
我有一個(gè)垂直滾動(dòng)的 TableView,我希望 ScrollBar 延伸到其父 AnchorPane 的頂部,并位于右上角填充方塊的頂部。請(qǐng)參閱下文,了解默認(rèn)情況下的情況。請(qǐng)注意,我的填充節(jié)點(diǎn)是白色的,這不是右上角的表列。在這行下面是我想要的,由另一個(gè)程序正確實(shí)現(xiàn)。我能夠通過(guò)以下方法實(shí)現(xiàn)這一目標(biāo):Platform.runLater(() ->{    ScrollBar someScrollBar = (ScrollBar) someTable.lookup(".scroll-bar:vertical");    someScrollBar.setTranslateY(-12);    someScrollBar.setScaleY(1.2);});其中 是在 FXML 中創(chuàng)建的表視圖,在控制器初始化函數(shù)中引用。someTable它看起來(lái)很好,但它不能正確縮放。如果包含的 AnchorPane 垂直調(diào)整大小,它看起來(lái)很糟糕。任何人都可以建議更好的方法來(lái)做到這一點(diǎn)嗎?非常感謝您抽出寶貴時(shí)間接受采訪。
查看完整描述

1 回答

?
嗶嗶one

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊

不支持滾動(dòng)條的自定義布局。我最初的評(píng)論是,你需要一個(gè)帶有自定義TableHeaderRow的自定義TableViewSkin:不幸的是,后者負(fù)責(zé)管理......好吧,tableHeader只是故事的一部分。

  • 一個(gè) TableHeaderRow 確實(shí)負(fù)責(zé)布置表頭

  • 但是:TableHeaderRow無(wú)法對(duì)垂直滾動(dòng)條進(jìn)行布局 - 當(dāng)它試圖在被覆蓋中這樣做時(shí),它會(huì)立即重置layoutChildren()

  • 重置發(fā)生在VirtualFlow(它是滾動(dòng)條的父級(jí))中

因此,在一天結(jié)束時(shí),我們需要

  • 一個(gè)自定義的 TableHeaderRow,表示需要放大和重新定位 scrollBar:下面的示例設(shè)置一個(gè)標(biāo)記,如果 scrollBar 可見(待定:檢查菜單按鈕是否可見),并在 scrollBar 的屬性映射中設(shè)置所需的額外高度

  • 一個(gè)自定義的VirtualFlow,可以處理標(biāo)記并根據(jù)需要實(shí)際進(jìn)行布局:下面的示例檢查標(biāo)記并在需要時(shí)調(diào)整大小/重新定位滾動(dòng)條。

  • 一個(gè)自定義的 TableViewSkin 來(lái)注入兩者(通過(guò)重寫的工廠方法)

該示例是針對(duì) fx11 編寫的,應(yīng)該適用于 fx10,但不適用于 fx9,因?yàn)楹笳卟辉试S提供自定義 VirtualFlow:

public class TableWithoutCorner extends Application {


    /**

     * Custom TableHeaderRow that requests a larger vbar height

     * if needed.

     */

    private static class MyTableHeader extends TableHeaderRow {


        private Region cornerAlias;

        private ScrollBar vBar;

        private TableViewSkinBase skin;


        public MyTableHeader(TableViewSkinBase skin) {

            super(skin);

            this.skin = skin;

        }


        @Override

        protected void layoutChildren() {

            super.layoutChildren();

            adjustCornerLayout();

        }


        private void adjustCornerLayout() {

            checkAlias();

            // tbd: check also if corner is visible

            if (!vBar.isVisible()) {

                vBar.getProperties().remove("DELTA");

            } else { 

                vBar.getProperties().put("DELTA", getHeight());

            }

        }


        private void checkAlias() {

            if (cornerAlias == null) {

                cornerAlias = (Region) lookup(".show-hide-columns-button");

            }

            if (vBar == null) {

                vBar = (ScrollBar) skin.getSkinnable().lookup(".scroll-bar:vertical");

            }

        }


    }


    /**

     * Custom VirtualFlow that respects additinal height for its 

     * vertical ScrollBar.

     */

    private static class MyFlow extends VirtualFlow {


        private ScrollBar vBar;

        private Region clip;


        public MyFlow() {

            // the scrollbar to adjust

            vBar = (ScrollBar) lookup(".scroll-bar:vertical");

            // the clipped container to use for accessing viewport dimensions

            clip = (Region) lookup(".clipped-container");


        }


        /**

         * Overridden to adjust vertical scrollbar's height and y-location

         * after calling super.

         */

        @Override

        protected void layoutChildren() {

            super.layoutChildren();

            adjustVBar();

        }


        /**

         * Adjusts vBar height and y-location by the height as

         * requested by the table header.

         */

        protected void adjustVBar() {

            if (vBar.getProperties().get("DELTA") == null) return;

            double delta = (double) vBar.getProperties().get("DELTA");

            vBar.relocate(clip.getWidth(), - delta);

            vBar.resize(vBar.getWidth(), clip.getHeight() + delta);

        }


    }


    /**

     * Boilerplate: need custom TableViewSkin to inject a custom TableHeaderRow and

     * custom VirtualFlow.

     */

    private static class MyTableViewSkin<T> extends TableViewSkin<T> {


        public MyTableViewSkin(TableView<T> control) {

            super(control);

        }


        @Override

        protected TableHeaderRow createTableHeaderRow() {

            return new MyTableHeader(this);

        }


        @Override

        protected VirtualFlow<TableRow<T>> createVirtualFlow() {

            return new MyFlow();

        }


    }


    private Parent createContent() {

        TableView<Locale> table = new TableView<>(FXCollections.observableArrayList(Locale.getAvailableLocales())) {


            @Override

            protected Skin<?> createDefaultSkin() {

                return new MyTableViewSkin(this);

            }


        }; 

        TableColumn<Locale, String> col = new TableColumn<>("Name");

        col.setCellValueFactory(new PropertyValueFactory<>("displayName"));

        table.getColumns().addAll(col);

        return table;

    }


    @Override

    public void start(Stage stage) throws Exception {

        stage.setScene(new Scene(createContent()));

        //stage.setTitle(FXUtils.version());

        stage.show();

    }


    public static void main(String[] args) {

        launch(args);

    }


    @SuppressWarnings("unused")

    private static final Logger LOG = Logger

            .getLogger(TableWithoutCorner.class.getName());


}


查看完整回答
反對(duì) 回復(fù) 2022-08-03
  • 1 回答
  • 0 關(guān)注
  • 266 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)