0
我试图创建一个取消按钮,它看起来是这样的:按钮:最小尺寸
因为十字架我目前使用的字母“X”。
现在我试图减少按钮中的空白空间,但我找不到摆脱垂直空间的方法。
目前,我有这样的事情:
package test;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
public class CancelButtonTestApplication extends Application {
@Override
public void start(Stage primaryStage) {
GridPane gridPane = new GridPane();
Label someLabel = new Label("Some Label:");
Button cancelButton = new Button("x");
cancelButton.setStyle("-fx-padding: 0.083333em 0.083333em 0.083333em 0.083333em;"); /* 1 1 1 1 */
cancelButton.setMaxHeight(Region.USE_PREF_SIZE);
someLabel.setLabelFor(cancelButton);
gridPane.add(someLabel, 0, 0);
gridPane.add(cancelButton, 1, 0);
gridPane.setHgap(5.0d);
GridPane.setVgrow(cancelButton, Priority.NEVER);
GridPane.setHgrow(cancelButton, Priority.NEVER);
Scene scene = new Scene(gridPane, 200, 50);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
它看起来像这样:
我使用套风格填充至1,1,1,1 AFAIK 你说的建议解决方案是使用负值进行填充?为什么这需要? – Puce
将填充设置为空看起来不正确,既不包含小x也不包含大写X. – Puce
我可以共享图像,这对我来说工作正常。我已经上传了包含我所做更改的图片。 – Optional