Bonjour.
J'ai une application que je développe en Java avec JavaFX.
J'ai une fenêtre principale qui contiens des onglet Tab dont un onglet n'est pas visible.Via un menu, je demande à afficher l'onglet "Administration" en passant par une fenêtre de connexion avec "login" et "mdp" relié à une base de données pour le login et le mdp (mais le problème n'est pas là) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 TabPane ongletPane = new TabPane(); Tab tabAdmin = new Tab(); tabAdmin.setText("Administration"); ongletPane.getTabs().remove(tabAdmin); ongletPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);et là, je me doute que vous devinez la question :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 package game; import dao.DAO; import dao.DAOFactory; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.stage.Modality; import javafx.stage.Stage; import pojo.Users; /** * * @author Flow */ public class LoginWindow extends Parent { public LoginWindow() { DAO<Users> userDao = DAOFactory.getUsersDAO(); Stage stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25,25,25,25)); Text scenetitle = new Text("Connexion à l'administration"); scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(scenetitle, 0, 0, 2, 1); Label userName = new Label("Login : "); grid.add(userName, 0, 1); TextField userTextField = new TextField(); grid.add(userTextField, 1, 1); Label pw = new Label("Mot de passe : "); grid.add(pw, 0, 2); PasswordField pwBox = new PasswordField(); grid.add(pwBox, 1, 2); Button btn = new Button("Se connecter"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); hbBtn.getChildren().add(btn); grid.add(hbBtn, 1, 4); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { String mdp = userDao.findByName(userTextField.getText()).getPassword(); if (mdp.equals(pwBox.getText())) { System.out.println("mdp correct"); }else{ Alert alert = new Alert(Alert.AlertType.WARNING); alert.setTitle(""); alert.setHeaderText(null); alert.setContentText("Mot de passe incorrect"); alert.showAndWait(); } } }); Scene scene = new Scene(grid, 300,275); stage.setScene(scene); stage.show(); } }
Comment puis-je afficher l'onglet masqué ??
Je vous mets quand même le code complet du main :Merci d'avance pour votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174 package game; import java.util.ArrayList; import java.util.List; import javafx.application.Application; import static javafx.application.Application.launch; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.NodeOrientation; import javafx.geometry.Side; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; import javafx.scene.control.RadioButton; import javafx.scene.control.RadioMenuItem; import javafx.scene.control.SeparatorMenuItem; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; /** * * @author Flow */ public class Kids_Games extends Application { @Override //Polymorphisme par héritage public void start(Stage primaryStage) { BorderPane root = new BorderPane(); Scene scene = new Scene(root, 1280, 800); // =============== Onglets ================= TabPane ongletPane = new TabPane(); ongletPane.setSide(Side.LEFT); BorderPane borderPane = new BorderPane(); Tab tabDessin = new Tab(); tabDessin.setText("Dessin"); ongletPane.getTabs().add(tabDessin); ongletPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); Tab tabCalcul = new Tab(); tabCalcul.setText("Calcul"); ongletPane.getTabs().add(tabCalcul); ongletPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); Tab tabQuestion = new Tab(); tabQuestion.setText("Question"); ongletPane.getTabs().add(tabQuestion); ongletPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); Tab tabAdmin = new Tab(); tabAdmin.setText("Administration"); ongletPane.getTabs().remove(tabAdmin); // ongletPane.getTabs().add(tabAdmin); ongletPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); Calcul calc = new Calcul(); tabCalcul.setContent(calc.CalculGUI()); Admin adminContent = new Admin(); tabAdmin.setContent(adminContent.initAdm()); QuestionsGUI questionGUI = new QuestionsGUI(); tabQuestion.setContent(questionGUI.questionsGUIinit()); TabDessin dess = new TabDessin(); tabDessin.setContent(dess); // =========================================== borderPane.prefHeightProperty().bind(scene.heightProperty()); borderPane.prefWidthProperty().bind(scene.widthProperty()); // ============== Menu ==================== MenuBar menuBar = new MenuBar(); SeparatorMenuItem separatorMenuItem = new SeparatorMenuItem(); SeparatorMenuItem separatorMenuItem2 = new SeparatorMenuItem(); //============Menu Niveau final List<String> levelString; levelString = new ArrayList<>(); levelString.add("Niveau 1"); levelString.add("Niveau 2"); // Picture Effect menu Menu menuNiveau = new Menu("Niveau"); final ToggleGroup groupEffect = new ToggleGroup(); RadioMenuItem itemNiveau1 = new RadioMenuItem("Niveau 1"); RadioMenuItem itemNiveau2 = new RadioMenuItem("Niveau 2"); //Construction menuNiveau.getItems().add(itemNiveau1); menuNiveau.getItems().add(itemNiveau2); //Added in others Menus //==============Other Menus final Menu fileMenu = new Menu("Fichier"); MenuItem dessin = new MenuItem("Dessin"); MenuItem calcul = new MenuItem("Calcul"); MenuItem question = new MenuItem("Question"); MenuItem exit = new MenuItem("Quitter"); MenuItem admin = new MenuItem("Administration"); //MenuItem niveau = new MenuItem("Niveau"); admin.setOnAction(e -> { e.consume(); LoginWindow connectAdmin = new LoginWindow(); }); fileMenu.getItems().add(dessin); fileMenu.getItems().add(calcul); fileMenu.getItems().add(question); fileMenu.getItems().add(separatorMenuItem); fileMenu.getItems().add(admin); fileMenu.getItems().add(menuNiveau); fileMenu.getItems().add(separatorMenuItem2); fileMenu.getItems().add(exit); exit.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { int code = 0; System.exit(code); } }); menuBar.getMenus().add(fileMenu); // =============================================== borderPane.setCenter(ongletPane); root.setCenter(borderPane); root.setTop(menuBar); primaryStage.setTitle("Jeux d'enfant"); scene.getStylesheets().add(Kids_Games.class.getResource("style.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }
Partager