java - 如何使用 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>
解决方案
您可以尝试负边距。
FXML
<?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>
推荐阅读
- wysiwyg - 添加列出所有文档的自定义图标,单击时应将其添加为链接
- python - 如何使用 Pymongo 将带有 collection.update_many() 的文档插入到 Collection (MongoDB) 中(不重复)
- php - 如果 PHP 中的运算符无法正常工作
- python - 加载冻结推理图以进行张量优化时无法导入元图
- php - SQL 在查询中获取所有用户活动的总和
- c# - Entity Framework Core - ForeingKey 显示空值
- r - 创建一个新变量,它是一个变量以其他两个变量为条件的平均值(并维护数据集中的所有其他变量)
- xml - 如何根据条件跳过 XML 中的节点并将该值添加到具有匹配条件的节点中
- shell - 如何避免在ggsci中删除重复时出现提示
- javascript - 如何在 jQuery click 上预加载下一个背景 css 图像?