vin*_*nay 4 user-interface javafx
我的组合框的下拉列表扩展到其中输入的最大元素的大小,但我希望它具有固定的大小.
---------------------
| Small Combobox | V |
--------------------------------------------
| "Long item 1" |
--------------------------------------------
| "Long item 2" |
--------------------------------------------
| "Long item 3" |
--------------------------------------------
Run Code Online (Sandbox Code Playgroud)
jew*_*sea 11
使用CSS
/** file: combo-size.css */
/** Size the combo-box button. */
.combo-box {
-fx-pref-width: 100;
}
/** Size the combo-box drop down list. */
.combo-box-popup > .list-view {
-fx-pref-width: 100;
}
Run Code Online (Sandbox Code Playgroud)
注:我只对Java的8测试此示例,我相信-fx-*-width和-fx-*-heightCSS属性可以为JavaFX 8是新的.
样本用法
在此示例中,组合框按钮和下拉列表都已调整为相同的首选宽度(100像素).

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class SizedComboBoxSampleWithCss extends Application {
public static void main(String[] args) { launch(args); }
@Override public void start(Stage stage) {
final ComboBox<String> combo = new ComboBox<>();
combo.setValue(Font.getDefault().getFamily());
combo.getItems().setAll(Font.getFamilies());
combo.getStylesheets().add(
getClass().getResource(
"combo-size.css"
).toExternalForm()
);
StackPane layout = new StackPane(combo);
layout.setPadding(new Insets(10));
stage.setScene(new Scene(layout));
stage.show();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13437 次 |
| 最近记录: |