一次扩展2个Titledpanes
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一次扩展2个Titledpanes相关的知识,希望对你有一定的参考价值。
在这些日子里,我将java swing代码重构为javafx。关于一些jpanel,我只是重构为JFXPanel,而JFXPanels`根是VBOX。 JFXPanel的结构是VBOX - > BorderPane - > TitledPane - > AnchorPane。
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="93.0" prefWidth="295.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<BorderPane prefHeight="259.0" prefWidth="309.0">
<top>
<TitledPane animated="false" prefHeight="93.0" prefWidth="297.0" style="-fx-background-color: #eeeeee;" text="Compensation Options" textFill="#1b75bc">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="295.0" prefWidth="267.0">
<children>
<Button fx:id="mResetCountButton" layoutX="25.0" layoutY="5.0" mnemonicParsing="false" text="Reset Counts" textAlignment="CENTER" />
<Button fx:id="plotStatsButton" layoutX="123.0" layoutY="5.0" mnemonicParsing="false" text="Stats Panel" textAlignment="CENTER" />
<Button fx:id="gateStatsButton" layoutX="208.0" layoutY="5.0" mnemonicParsing="false" text="Gate State" textAlignment="CENTER" />
<Button fx:id="mLoadMatrixButton" layoutX="28.0" layoutY="37.0" mnemonicParsing="false" text="Load Matrix" textAlignment="CENTER" />
<Button fx:id="viewCompMatrix" layoutX="119.0" layoutY="37.0" mnemonicParsing="false" text="View Matrix" textAlignment="CENTER" />
<Label fx:id="mJCompMatrixCombo" layoutX="208.0" layoutY="41.0" text="Matrix Name" />
</children>
</AnchorPane>
</content>
</TitledPane>
</top>
</BorderPane>
</children>
</VBox>
而现在我想将JFXPanels作为Accordion。当我在谷歌搜索时,我刚看到一些使用的代码,当我制作Accordion标签时,我只能在标签下方使用TitledPane。有没有其他方法可以让JFXPanels作为Accordion重用我的代码?...
实际上使用Tag,我只需要一次扩展一个名为Tape的。如何使用Accordion制作JavaFX应用程序,它可以同时扩展许多titledPanes?
我只是尝试制作标题为Panesclicklistener and resizing VBox which is wrapping titledPane and titledpane
s尺寸和一些在标题窗格内的窗格。
如
boolean titledPaneClicked = false;
TiteldPane.setOnAction((e)->{
if(titledPaneClicked){
TitledPane.setHeight(0);
Vbox.setHeight(0);
soemotherPanes.setHeight(0);
titledPaneClicked = !titledPaneClicked;
}else{
TitledPane.setHeight(previousSize);
Vbox.setHeight(previousSize);
soemotherPanes.setHeight(previousSize);
titledPaneClicked = !titledPaneClicked;
}
});
它没有用。 Plz帮帮我:)
如果您的问题是关于如何一次打开关闭2 TitledPane
s,您可以通过编程方式执行此操作,例如使用按钮:
Main.fxml(使您的代码mcve始终发布fxml名称并导入)
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<VBox minWidth="-Infinity" prefHeight="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="tests.xml.Controller">
<children>
<BorderPane>
<top>
<TitledPane fx:id="aTitledPane" animated="false" style="-fx-background-color: #eeeeee;" text="Compensation Options" textFill="#1b75bc">
<content>
<AnchorPane>
<children>
<Label text="Top pane expanded" />
</children>
</AnchorPane>
</content>
</TitledPane>
</top>
<center>
<TitledPane fx:id="bTitledPane" animated="false" style="-fx-background-color: #eeeeee;" text="Other Options" textFill="#1b75bc">
<content>
<AnchorPane>
<children>
<Label text="Bottom pane expanded" />
</children>
</AnchorPane>
</content>
</TitledPane>
</center>
<bottom>
<Button fx:id="openCloseButton" onAction="#openClose" text="Close" textAlignment="CENTER" />
</bottom>
</BorderPane>
</children>
</VBox>
它控制器:
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TitledPane;
public class Controller {
@FXML
private TitledPane aTitledPane, bTitledPane;
@FXML
private Button openCloseButton;
private final static String OPEN = "Open", CLOSE = "Close";
@FXML
void initialize(){
openCloseButton.setText(OPEN);
aTitledPane.setExpanded(false);
bTitledPane.setExpanded(false);
}
@FXML
private void openClose(){
System.out.println(openCloseButton.getText());
if(openCloseButton.getText().equals(OPEN)){
openCloseButton.setText(CLOSE);
aTitledPane.setExpanded(true);
bTitledPane.setExpanded(true);
}else{
openCloseButton.setText(OPEN);
aTitledPane.setExpanded(false);
bTitledPane.setExpanded(false);
}
}
}
测试使用:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class FXMLTest extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("xml/Main.fxml"));
primaryStage.setTitle("Hello World");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(null);
}
}
如果你想要打开/关闭一个TitledPane
将打开/关闭另一个而不使用按钮,从fxml中删除按钮,并绑定控制器中两个TitledPane.expandedProperty()
s的TitledPane
:
import javafx.fxml.FXML;
import javafx.scene.control.TitledPane;
public class Controller {
@FXML
private TitledPane aTitledPane, bTitledPane;
@FXML
void initialize(){
aTitledPane.expandedProperty().bindBidirectional(bTitledPane.expandedProperty());
}
}
我只是使用VBox解决了这个问题。
我制作了VBox,名为Pane和VBox,其中包含一些Btns,Labels等等。
VBox mainBox = new VBox();
TitledPane T1 = new TitledPane();
VBox content1 = new VBox();
T1.setContent(content1);
TitledPane T2 = new TitledPane();
VBox content2 = new VBox();
T2.setContent(content2);
mainBox.getChildren().addAll(T1, T2);
然后在MainVBox中,titledPanes显示为手风琴。
以上是关于一次扩展2个Titledpanes的主要内容,如果未能解决你的问题,请参考以下文章