仅当鼠标单击两次时,我才想展开/折叠标题窗格...我尝试了以下操作,但不起作用
如果单击两次,标题窗格将展开/折叠。但是如果只有一次,则信息窗格将更新其内容。
package DummyGUI;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;
import javafx.event.ActionEvent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class App extends Application
{
private final VBox infoPane;
private final Image male = new Image(getClass().getResourceAsStream("male.png"), 16, 16, true, true);
private final Image female = new Image(getClass().getResourceAsStream("female.png"), 16, 16, true, true);
public static void main(String[] args)
{
launch();
}
public void start(Stage topView)
{
createGUI(topView);
}
private void handleAcc(MouseEvent e, TitledPane p, Person r)
{
if(e.getClickCount() == 1)
{
updateInfoPane(r);
}
else if(e.getClickCount() > 1)
{
p.setExpanded(true);
}
}
private void updateInfoPane()
{
// update info pane
}
private void createGUI(Stage topView)
{
topView.setTitle("Dummy App");
Accordion accordion = new Accordion();
Person r = new Person("Maria", "Kim");
VBox vb = new VBox();
infoPane = new VBox();
Node nd = (Node)vb;
TitledPane tp = new TitledPane(r.getFName() + " " + r.getSurname(), nd);
tp.setOnMouseClicked(e -> handleAcc(e, tp, r));
tp.setOnMousePressed(e -> handleAcc(e, tp, r));
tp.setOnMouseReleased(e -> handleAcc(e, tp, r));
tp.setOnMouseEntered(e -> handleAcc(e, tp, r));
accordion.getPanes().add(tp);
vb.getChildren().addAll(accordion, infoPane);
topView.setScene(new Scene(vb));
topView.show();
}
问题是,单击1会使其仍然展开/折叠,并且信息窗格同时更新。如何使其仅在2次点击中展开/折叠?谢谢