[英]How to remove the padding of a button with nested label with JavaFX CSS
如您所见,标签(“a123”)嵌套在按钮中。 由于标签具有背景颜色,我希望它能够吞没按钮的整个高度和左侧。 你能建议正确的方法吗?
现在的情况:
期望:
我的解决方案:
<Button fx:id="rootContainer" alignment="TOP_LEFT" graphicTextGap="10.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="30.0" prefWidth="190.0" stylesheets="@../../../commons/util/resources/myCSS.css" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="app.features.dashboard.userorder.UserOrderPresenter">
<graphic>
<HBox alignment="CENTER" spacing="10.0">
<children>
<Label fx:id="labelTableName" alignment="CENTER_RIGHT" contentDisplay="CENTER" focusTraversable="false" maxHeight="1.7976931348623157E308" maxWidth="-Infinity" prefWidth="70.0" styleClass="label-table-number" text="a123" textFill="WHITE">
<HBox.margin>
<Insets bottom="-8.0" left="-15.0" top="-8.0" />
</HBox.margin>
</Label>
<HBox alignment="CENTER_LEFT" spacing="5.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</graphic>
</Button>
你可以尝试负利润率。
文件格式
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0">
<graphic>
<HBox>
<children>
<Label maxHeight="1.7976931348623157E308" style="-fx-background-color: black; -fx-text-fill: white;" text="Label">
<HBox.margin>
<Insets bottom="-3.0" left="-7.0" right="-3.0" top="-3.0" />
</HBox.margin>
<padding>
<Insets left="5.0" right="5.0" />
</padding>
</Label>
</children>
</HBox>
</graphic>
</Button>
</children>
</StackPane>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.