Just trying to learn JavaFX and my goal of this is to have the splitpane divider move all the way to the right if the "Hide Terminal" button is clicked. Here is what I've set up in Scene Builder:
只是尝试学习JavaFX,我的目标是在单击“隐藏终端”按钮的情况下让splitpane分隔符一直向右移动。这是我在Scene Builder中设置的内容:
I tried adding code to the initialise() method and can confirm that runs.
我尝试将代码添加到initialise()方法并确认运行。
Here is the code that's supposed to be triggered from the On Mouse Clicked event:
这是应该从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");
}
}
The FXML itself:
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 个解决方案
#1
1
For the if condition if you want to hide the divider, initial position of the divider should be greater than 0.99 and in your attached picture it seems that it's less than 0.99. So in this case you should change the if condition like this
对于if条件,如果要隐藏分隔符,则分隔符的初始位置应大于0.99,并且在附加的图片中,它似乎小于0.99。所以在这种情况下你应该像这样改变if条件
if(mainWindow.getDividerPositions()[0] < 0.99)
{
mainWindow.setDividerPositions(0.7);
terminalHideShowLabel.setText("Hide Terminal");
}
I don't know what your desired criteria for hiding the divider ... so change your if and else statement like that way. I just mentioned the example in basis of you attached image
我不知道你想要隐藏分隔符的标准是什么...所以改变你的if和else语句是这样的。我刚才提到了你附图中的例子
#2
0
Determined that in order to be able to click the ImageView I had to set the Pick On Bounds options for it, as the transparency parts wasn't clickable, which was most of the arrow picture.
确定为了能够点击ImageView我必须为它设置Pick On Bounds选项,因为透明度部分不可点击,这是箭头图片的大部分。
For whatever reason also, the ImageView is prevented from being clicked whilst wrapped by a label object. Moving the Label and ImageView to separate objects fixed the main issue, even though you can still set action handlers to them whilst "wrapped".
无论出于何种原因,在被标签对象包裹时都不会单击ImageView。将Label和ImageView移动到单独的对象来修复主要问题,即使你仍然可以在“包裹”时为它们设置动作处理程序。
#1
1
For the if condition if you want to hide the divider, initial position of the divider should be greater than 0.99 and in your attached picture it seems that it's less than 0.99. So in this case you should change the if condition like this
对于if条件,如果要隐藏分隔符,则分隔符的初始位置应大于0.99,并且在附加的图片中,它似乎小于0.99。所以在这种情况下你应该像这样改变if条件
if(mainWindow.getDividerPositions()[0] < 0.99)
{
mainWindow.setDividerPositions(0.7);
terminalHideShowLabel.setText("Hide Terminal");
}
I don't know what your desired criteria for hiding the divider ... so change your if and else statement like that way. I just mentioned the example in basis of you attached image
我不知道你想要隐藏分隔符的标准是什么...所以改变你的if和else语句是这样的。我刚才提到了你附图中的例子
#2
0
Determined that in order to be able to click the ImageView I had to set the Pick On Bounds options for it, as the transparency parts wasn't clickable, which was most of the arrow picture.
确定为了能够点击ImageView我必须为它设置Pick On Bounds选项,因为透明度部分不可点击,这是箭头图片的大部分。
For whatever reason also, the ImageView is prevented from being clicked whilst wrapped by a label object. Moving the Label and ImageView to separate objects fixed the main issue, even though you can still set action handlers to them whilst "wrapped".
无论出于何种原因,在被标签对象包裹时都不会单击ImageView。将Label和ImageView移动到单独的对象来修复主要问题,即使你仍然可以在“包裹”时为它们设置动作处理程序。