JavaFX TabPane从外部控制器中选择选项卡
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaFX TabPane从外部控制器中选择选项卡相关的知识,希望对你有一定的参考价值。
我在此有用的帖子(PASSING PARAMETERS JAVAFX FXML)的开头更改了代码之后,我的setTab函数无法正常工作。它被调用,但没有执行应做的操作。
Main.java
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage){
Controller1 controller1 = new Controller1();
controller1.showStage();
}
}
Controller1.java
public class Controller1{
private final Stage thisStage;
private Controller2 controller2 = new Controller2(this);
public Controller1() {
thisStage = new Stage();
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Steuerung.fxml"));
loader.setController(this);
thisStage.setScene(new Scene(loader.load()));
thisStage.setTitle("Steuerung");
}catch (IOException e){
e.printStackTrace();
}
}
public void showStage(){ thisStage.show();}
@FXML private void initialize() {
b_AnzeigeÖffnen.setOnAction(e -> openAnzeige());
b_Ecke_Eingabe.setOnAction(e -> controller2.setTab(2));
}
private void openAnzeige(){
Controller2 controller2 = new Controller2(this);
controller2.showStage();
}
//Formatierungshinweis: b(Button; meist eigentlich Label(oder Menüpunkt), aber aus Designgründen als Button benutzt und deswegen auch beschriftet)
@FXML
private Menu b_Menü_Fenster;
@FXML
private MenuItem b_AnzeigeÖffnen;
@FXML
private MenuItem b_AllesSchließen;
@FXML
private Menu b_Menü_Menü;
@FXML
private MenuItem b_MStartseite;
@FXML
private MenuItem b_MTor;
@FXML
private Menu b_MKarte;
@FXML
private MenuItem b_MGelbeKarte;
@FXML
private MenuItem b_MRoteKarte;
@FXML
private MenuItem b_MAuswechselung;
@FXML
private MenuItem b_MEcke;
@FXML
private MenuItem b_MElfmeter;
@FXML
private MenuItem b_MNachspielzeit;
@FXML
private Menu b_Menü_Hilfe;
@FXML
private MenuItem b_Über;
@FXML
private Label b_Startseite;
@FXML
private Label b_Tor;
@FXML
private Label b_GelbeKarte;
@FXML
private Label b_RoteKarte;
@FXML
private Label b_Auswechselung;
@FXML
private Label b_Ecke;
@FXML
private Label b_Elfmeter;
@FXML
private Label b_Nachspielzeit;
@FXML
private TabPane TP_AktuellesMenü;
@FXML
private Tab t_Startseite;
@FXML
private Label Anzeige_AktuellesMenü;
@FXML
private Label l_Timer;
@FXML
private Label l_Spielstand1;
@FXML
private Tab t_Tor;
@FXML
private Label Anzeige_AktuellesMenü1;
@FXML
private CheckBox CB_Heim;
@FXML
private CheckBox CB_Gast;
@FXML
private TextField tf_Spielernummer;
@FXML
private TextField tf_Spielername;
@FXML
private Button b_Tor_Eingabe;
@FXML
private Label Anzeige_AktuellesMenü11;
@FXML
private Button b_TorAnnulation_Eingabe;
@FXML
private Label l_Spielstand;
@FXML
private Tab t_GelbeKarte;
@FXML
private Label Anzeige_AktuellesMenü2;
@FXML
private CheckBox CB_GKHeim;
@FXML
private CheckBox CB_GKGast;
@FXML
private TextField tf_GKSpielernummer;
@FXML
private TextField tf_GKSpielername;
@FXML
private Button b_GK_Eingabe;
@FXML
private Tab t_RoteKarte;
@FXML
private Label Anzeige_AktuellesMenü3;
@FXML
private CheckBox CB_RKHeim;
@FXML
private CheckBox CB_RKGast;
@FXML
private TextField tf_RKSpielernummer;
@FXML
private TextField tf_RKSpielername;
@FXML
private Button b_RK_Eingabe;
@FXML
private Tab t_Auswechselung;
@FXML
private Label Anzeige_AktuellesMenü4;
@FXML
private CheckBox CB_A_Heim;
@FXML
private CheckBox CB_A_Gast;
@FXML
private TextField tf_AA_Spielernummer;
@FXML
private TextField tf_AA_Spielername;
@FXML
private TextField tf_AE_Spielernummer;
@FXML
private TextField tf_AE_Spielername;
@FXML
private Button tf_A_Eingabe;
@FXML
private Tab t_Ecke;
@FXML
private Label Anzeige_AktuellesMenü5;
@FXML
private CheckBox CB_ECKE_Heim;
@FXML
private CheckBox CB_ECKE_Gast;
@FXML
private Button b_Ecke_Eingabe;
@FXML
private Tab t_Elfmeter;
@FXML
private Label Anzeige_AktuellesMenü6;
@FXML
private Tab t_Nachspielzeit;
@FXML
private Label Anzeige_AktuellesMenü7;
@FXML
private Label Anzeige_AktuellesMenü71;
@FXML
private TextField tf_Machspielzeit_Länge;
@FXML
private Button b_Nachspielzeit_Eingabe;
@FXML
private CheckBox CheckBox_Verlängerung;
@FXML
private Label l_Spielzeit;
@FXML
private Label l_NormaleZeit;
@FXML
private Button b_Abseits_Heim;
@FXML
private Button b_Abseits_Gast;
@FXML
private Button b_Abseits_Annulation;
@FXML
private CheckBox CB_AbseitsZählen;
@FXML
private CheckBox CB_ElH;
@FXML
private CheckBox CB_ElG;
@FXML
private Button b_El_Eingabe;
@FXML
private Button b_Zuschauerzahl_Eingabe;
@FXML
private TextField tf_Zuschauerzahl;
@FXML
public Button b1;
/*@FXML
void AnzeigeÖffnen(ActionEvent event){
try {
FXMLLoader loaderAnzeige = new FXMLLoader(getClass().getResource("../projekt.fxml/Anzeige.projekt.fxml"));
Parent root = loaderAnzeige.load();
this.controller2 = loaderAnzeige.getController();
this.controller2.setController1(this);
Stage stage = new Stage();
stage.setTitle("Anzeige");
stage.setScene(new Scene(root, 800, 600));
stage.show();
}
catch (IOException e) {
e.printStackTrace();}
}*/
@FXML
void AnzeigeSchließen(ActionEvent event){
Platform.exit();
}
@FXML
void AbseitsZählen(ActionEvent event){
if(CB_AbseitsZählen.isSelected()==false){
b_Abseits_Annulation.setVisible(false);
b_Abseits_Gast.setVisible(false);
b_Abseits_Heim.setVisible(false);
}else if(CB_AbseitsZählen.isSelected()==true){
b_Abseits_Annulation.setVisible(true);
b_Abseits_Gast.setVisible(true);
b_Abseits_Heim.setVisible(true);
}
}
@FXML
void CBGedrückt_TorH(ActionEvent event){
if (CB_Heim.isSelected()==true) CB_Gast.setSelected(false);
}
@FXML
void CBGedrückt_TorG(ActionEvent event){
if (CB_Gast.isSelected()==true) CB_Heim.setSelected(false);
}
@FXML
void CBGedrückt_GKH(ActionEvent event){
if (CB_GKHeim.isSelected()==true) CB_GKGast.setSelected(false);
}
@FXML
void CBGedrückt_GKG(ActionEvent event){
if (CB_GKGast.isSelected()==true) CB_GKHeim.setSelected(false);
}
@FXML
void CBGedrückt_RKH(ActionEvent event){
if (CB_RKHeim.isSelected()==true) CB_RKGast.setSelected(false);
}
@FXML
void CBGedrückt_RKG(ActionEvent event){
if (CB_RKGast.isSelected()==true) CB_RKHeim.setSelected(false);
}
@FXML
void CBGedrückt_AH(ActionEvent event){
if (CB_A_Heim.isSelected()==true) CB_A_Gast.setSelected(false);
}
@FXML
void CBGedrückt_AG(ActionEvent event){
if (CB_A_Gast.isSelected()==true) CB_A_Heim.setSelected(false);
}
@FXML
void CBGedrückt_EH(ActionEvent event){
if (CB_ECKE_Heim.isSelected()==true) CB_ECKE_Gast.setSelected(false);
}
@FXML
void CBGedrückt_EG(ActionEvent event){
if (CB_ECKE_Gast.isSelected()==true) CB_ECKE_Heim.setSelected(false);
}
@FXML
void CBGedrückt_ElH(ActionEvent event){
if (CB_ElH.isSelected()==true) CB_ElG.setSelected(false);
}
@FXML
void CB_Gedrückt_ElG(ActionEvent event){
if(CB_ElG.isSelected()==true) CB_ElH.setSelected(false);
}
//Methoden zur Farbänderung des jeweiligen Labels in der rechten Menüleiste, wenn auf das entsprechende Label geklickt wird
//Formatierung: Menü(rechte Menüspalte)XY(Anfangsbuchstaben des jeweiligen Labels)Gedrückt
@FXML
void MenüSGedrückt(MouseEvent event) {
b_Startseite.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Startseite);
}
@FXML
void MenüAGedrückt(MouseEvent event) {
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Auswechselung);
// controller2.TP_A.getSelectionModel().select(tA);
}
@FXML
void MenüEGedrückt(MouseEvent event) {
b_Ecke.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Ecke);
}
@FXML
void MenüElGedrückt(MouseEvent event) {
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Elfmeter);
}
@FXML
void MenüGGedrückt(MouseEvent event) {
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_GelbeKarte);
}
@FXML
void MenüNGedrückt(MouseEvent event) {
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Nachspielzeit);
}
@FXML
void MenüRGedrückt(MouseEvent event) {
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_RoteKarte);
}
@FXML
void MenüTGedrückt(MouseEvent event) {
b_Tor.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Tor);
}
//Methoden zur Farbänderung der Label in der rechten Menüleiste, wenn ein Menüpunkt in der KopfMenüzeile geklickt wurde
//Formatierung: M(Menübar)M(Menüpunkt)XY(Anfangsbuchstaben des jeweiligen Buttons)Gedrückt
@FXML
void MMAGedrückt(ActionEvent event) {
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Auswechselung);
}
@FXML
void MMEGedrückt(ActionEvent event) {
b_Ecke.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Ecke);
}
@FXML
void MMElGedrückt(ActionEvent event) {
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Elfmeter);
}
@FXML
void MMGGedrückt(ActionEvent event) {
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_GelbeKarte);
}
@FXML
void MMNGedrückt(ActionEvent event) {
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Nachspielzeit);
}
@FXML
void MMRGedrückt(ActionEvent event) {
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_RoteKarte);
}
@FXML
void MMSGedrückt(ActionEvent event) {
b_Startseite.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Tor.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Startseite);
}
@FXML
void MMTGedrückt(ActionEvent event) {
b_Tor.setBackground(new Background(new BackgroundFill(Color.LIGHTGREY, CornerRadii.EMPTY, Insets.EMPTY)));
b_Nachspielzeit.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Startseite.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Auswechselung.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Ecke.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_Elfmeter.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_GelbeKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
b_RoteKarte.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
TP_AktuellesMenü.getSelectionModel().select(t_Tor);
}
}
Controller2.java
public class Controller2 {
private Stage thisStage;
private final Controller1 controller1;
public Controller2(Controller1 controller1) {
this.controller1 = controller1;
thisStage = new Stage();
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Anzeige.fxml"));
loader.setController(this);
thisStage.setScene(new Scene(loader.load()));
thisStage.setTitle("Spielstand");
}catch (IOException e){
e.printStackTrace();
}
}
public void showStage() { thisStage.show();}
@FXML
private TabPane TP_A;
@FXML
private Tab tA_Home;
@FXML
private Tab tA_EckePreview;
@FXML
private Tab tA_EckVerhältnis;
@FXML
private Tab tA_Spielverlauf;
@FXML
private Tab tA_Spielstatistik;
@FXML
private Tab tA_GelbeKarte;
@FXML
private Tab tA_RoteKarte;
@FXML
private Tab tA_Elfmeter;
@FXML
private Tab tA_Auswechselung;
@FXML public void setTab(Integer i) {
System.out.println("TABSWITCH");
switch(i) {
case 1: TP_A.getSelectionModel().select(tA_Home); break;
case 2: TP_A.getSelectionModel().select(tA_EckePreview); break;
case 3: TP_A.getSelectionModel().select(tA_EckVerhältnis); break;
case 4: TP_A.getSelectionModel().select(tA_Spielverlauf); break;
case 5: TP_A.getSelectionModel().select(tA_Spielstatistik); break;
case 6: TP_A.getSelectionModel().select(tA_GelbeKarte); break;
case 7: TP_A.getSelectionModel().select(tA_RoteKarte); break;
case 8: TP_A.getSelectionModel().select(tA_Elfmeter); break;
case 9: TP_A.getSelectionModel().select(tA_Auswechselung); break;
//case 10: TP_A.getSelectionModel().select(tA_Nachspielzeit/Verlängerung); break; -> TODO
default: System.out.println("Fehler: Tab in TP_A nicht vorhanden!"); break;
}
}
}
!包装和进口件的车身长度已被删除!
我知道我必须重写最后几个函数,因为它们很容易合而为一。
Steuerung.fxml和Anzeige.fxml太长了。如果您想看到它们,这是完整的GitLab项目。GitLab Project
对不起,德语注释,函数/变量名和/或对象
感谢您的建议!
编辑:语法
答案
Controller1.java
public class Controller1{
private final Stage thisStage;
private Controller2 controller2 = new Controller2(this);
public Controller1() {
thisStage = new Stage();
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Steuerung.fxml"));
loader.setController(this);
thisStage.setScene(new Scene(loader.load()));
thisStage.setTitle("Steuerung");
}catch (IOException e){
e.printStackTrace();
}
}
public void showStage(){ thisStage.show();}
@FXML private void initialize() {
b_AnzeigeÖffnen.setOnAction(e -> openAnzeige());
b_Ecke.setOnMouseClicked(e -> controller2.setTab(2));
}
private void openAnzeige(){
Controller2 controller2 = new Controller2(this);
controller2.showStage();
}
@FXML
private Label b_Ecke;
@FXML
private MenuItem b_AnzeigeÖffnen
}
更好?
以上是关于JavaFX TabPane从外部控制器中选择选项卡的主要内容,如果未能解决你的问题,请参考以下文章
带有 StackPane 和自定义控件的 Javafx TabPane