使用JFoenix库,有没有办法让切换按钮像普通的JavaFX ToggleButton
那样是一个矩形?
JFXToggleButton
看起来更像是一个开关 - 而这不是我想要的。
答案 0 :(得分:0)
感谢您提出,自我。我也想知道同样的事情。
要制作类似于普通ToggleButon
的东西,你可以在JFoenix中使用名为JFXToggleNode
的鲜为人知的控件。
正如您在the JFoenix Demo中看到的,此控件通常包含一个图标。
但是你可以把你想要的任何东西放进去。 为什么不是标签?
小心不要忘记包含import
语句,只需手动将 § 添加到FXML文件中。
<?import com.jfoenix.controls.JFXToggleNode?>
<?import javafx.scene.control.Label?>
...
<JFXToggleNode>
<Label text="Boton Azul" />
</JFXToggleNode>
并将此规则添加到样式表中:
.jfx-toggle-node {
/* This is the color once toggled on. */
-jfx-toggle-color: deepskyblue;
}
§:请注意,SceneBuilder不支持非标准控件,但是,虽然无法拖放它,但可以手动将其添加到FXML文件中就好了。
答案 1 :(得分:0)
这是我自定义的JFXToggleNode实现
使用所需的任何图标包
import com.jfoenix.controls.JFXToggleNode;
import de.jensd.fx.glyphs.materialicons.MaterialIcon;
import de.jensd.fx.glyphs.materialicons.MaterialIconView;
import javafx.scene.paint.Paint;
public class ShowPasswordButton extends JFXToggleNode {
private MaterialIconView visible = new MaterialIconView(MaterialIcon.VISIBILITY, "20");
private MaterialIconView notVisible = new MaterialIconView(MaterialIcon.VISIBILITY_OFF, "20");
public ShowPasswordButton() {
super();
this.init();
this.setGraphic(visible);
this.selectedProperty().addListener((observable, oldValue, newValue) ->
this.setGraphic(newValue ? notVisible : visible));
}
private void init() {
visible.setFill(Paint.valueOf("#46a28d"));
notVisible.setFill(Paint.valueOf("#46a28d"));
}
}