只是尝试学习JavaFX,我的目标是在单击"Hide Terminal"按钮时让splitpane分隔符一直向右移动 . 这是我在Scene Builder中设置的内容:
我尝试将代码添加到initialise()方法并确认运行 .
这是应该从On Mouse Clicked事件触发的代码:
@FXML
void terminalHideShow(MouseEvent event) {
terminalHideShowButton.rotateProperty().setValue(180.0);
terminalCommandListOutput.getItems().add("TEXT"); // a test
if(mainWindow.getDividerPositions()[0] > 0.99)
{
mainWindow.setDividerPositions(0.7);
terminalHideShowLabel.setText("Hide Terminal");
}
else
{
mainWindow.setDividerPositions(1.0);
terminalHideShowLabel.setText("Show Terminal");
}
}
FXML本身:
<Label alignment="CENTER_RIGHT" contentDisplay="RIGHT" nodeOrientation="LEFT_TO_RIGHT" text="Hide Terminal" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<graphic>
<ImageView fx:id="terminalHideShowButton" accessibleRole="BUTTON" onMouseClicked="#terminalHideShow" rotate="180.0">
<image>
<Image url="@../images/angle-right-circle.png" />
</image>
</ImageView>
</graphic>
</Label>
2 回答
对于if条件,如果要隐藏分隔符,则分隔符的初始位置应大于0.99,并且在附加的图片中,它似乎小于0.99 . 所以在这种情况下你应该像这样改变if条件
我不知道你想要隐藏分隔符的标准是什么...所以改变你的if和else语句是这样的 . 我刚才提到你附图中的例子
确定为了能够单击ImageView,我必须为它设置Pick On Bounds选项,因为透明度部分不可点击,这是大部分箭头图片 .
无论出于何种原因,都会阻止ImageView在被标签对象包裹时被点击 . 将Label和ImageView移动到单独的对象来修复主要问题,即使你仍然可以在“包裹”时为它们设置动作处理程序 .