当前位置: 动力学知识库 > 问答 > 编程问答 >

java - JavaFX: Optimized way to give nodes fixed width / dimension?

问题描述:

How do I give all my buttons the same width? These buttons have a VBox as a container. First I tried setMaxWidth with max value which works well:

this.button1.setMaxWidth(Double.MAX_VALUE);

this.button2.setMaxWidth(Double.MAX_VALUE);

this.button3.setMaxWidth(Double.MAX_VALUE);

this.button4.setMaxWidth(Double.MAX_VALUE);

Ideally I would like to set this in my css file to keep my code clean from any design aspect. I find that there is an aweful lot of repetition going on here so how can I do this with 1 line of code? Something like:

.button {

-fx-width: 50pt;

}

网友答案:

This does the trick:

.button {
    -fx-pref-width: 50px;
}

More details here

网友答案:

Here http://docs.oracle.com/javafx/2/css_tutorial/jfxpub-css_tutorial.htm

Selectors

Several types of styles can be defined. Each type of style has its own convention for selectors.

Style classes correspond to class names. By convention, style class names that consist of more than one word use a hyphen (-) between words. Style class selectors are preceded by a dot (.).

Examples of class selectors:

.button .check-box .scroll-bar

The same for JavaFX 8. Check your code, mistake somewhere else.

分享给朋友:
您可能感兴趣的文章:
随机阅读: