Bonsoir ....j'ai une probléme .....!!! j'ai preparé un menue Bar par Scene Builder ..et j'ai pas compris comment integrer un Internal frame Classe avec sa Desktop classe
sur javaFx dans laquelle l'utilisateur clique par exemple sur le menue item 1 ''Fichier'' et ouvre une InternalFrame dans le Border Pane ..Or certain m'a dit qui'l n'ya pas du JdesktopPanel dans javaFx
Menue Bar prépare par scene Builder fxml file ==>
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 <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Menu?> <?import javafx.scene.control.MenuBar?> <?import javafx.scene.control.MenuItem?> <?import javafx.scene.control.SeparatorMenuItem?> <?import javafx.scene.effect.DropShadow?> <?import javafx.scene.layout.BorderPane?> <BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/8.0.102" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController"> <top> <MenuBar BorderPane.alignment="CENTER"> <menus> <Menu id="file" mnemonicParsing="false" text="File"> <items> <MenuItem id="Open Tornado project" mnemonicParsing="false" text="Open Tornado project" /> <SeparatorMenuItem mnemonicParsing="false" /> <Menu id="recent project" mnemonicParsing="false" text="Open Recent Tornado Project"> <items> <MenuItem id="no recent... " mnemonicParsing="false" text="No recent Project .... " /> </items> </Menu> <SeparatorMenuItem mnemonicParsing="false" /> <Menu id="Open specified File..." mnemonicParsing="false" text="Open specified File ......"> <items> <MenuItem id="°C" mnemonicParsing="false" text="Temperature Graph °C" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="hPa" mnemonicParsing="false" text="Pression Graph (hPa)" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="humidity" mnemonicParsing="false" text="Humidity Graph" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Ping Graph" mnemonicParsing="false" text="Ping Graph" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="map" mnemonicParsing="false" text="Map " /> </items> </Menu> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="open Cloud" mnemonicParsing="false" text="Open Project's Cloud" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Save your Project " mnemonicParsing="false" text="Save your Project " /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Quit" mnemonicParsing="false" onAction="#CloseApp" text="Quit" /> </items> </Menu> <Menu id="edit" mnemonicParsing="false" text="Edit"> <items> <MenuItem id="Copy CTRL+C" mnemonicParsing="false" text="Copy CTRL+C" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Cut CTRL+X" mnemonicParsing="false" text="Cut CTRL+X" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id=" Delete Delete" mnemonicParsing="false" text="Delete Delete" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Select All CTRL+A" mnemonicParsing="false" text="Select All CTRL+A" /> </items> </Menu> <Menu id="Show" mnemonicParsing="false" text="Show"> <items> <MenuItem id="Timer" mnemonicParsing="false" text="Timer" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="File Explorer" mnemonicParsing="false" text="File Explorer" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Custom Run" mnemonicParsing="false" text="Custom Run" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Ballls/State" mnemonicParsing="false" text="Ballls/State" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Graph per Srceen !" mnemonicParsing="false" text="Graph per Srceen !" /> </items> </Menu> <Menu id="RUN" mnemonicParsing="false" text="RUN"> <items> <MenuItem id="Storm Ball " mnemonicParsing="false" text="Storm Ball (-_-) " /> <SeparatorMenuItem mnemonicParsing="false" /> <Menu id="wakeup " mnemonicParsing="false" text="WakeUp Mode"> <items> <MenuItem id="step Zero" mnemonicParsing="false" text="Step_Zero Data" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="ping" mnemonicParsing="false" text=" ==> Ping ...<==" /> </items> </Menu> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="auto" mnemonicParsing="false" text="Auto Mode " /> </items> </Menu> <Menu id="magic" mnemonicParsing="false" text="***Magic Button ***"> <items> <MenuItem id="Set time" mnemonicParsing="false" text="Set Function Timer" /> <SeparatorMenuItem mnemonicParsing="false" /> <Menu id="get data" mnemonicParsing="false" text="Get Data"> <items> <MenuItem id="Temperature Graph °C" mnemonicParsing="false" text="Temperature Graph °C" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Pression Graph (hPa)" mnemonicParsing="false" text="Pression Graph (hPa)" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Humidity Graph " mnemonicParsing="false" text="Humidity Graph " /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Position Mapping" mnemonicParsing="false" text="Position Mapping" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem id="Storm Ball Altitude Graph" mnemonicParsing="false" text="Storm Ball Altitude Graph" /> </items> </Menu> </items> </Menu> <Menu id="Help" mnemonicParsing="false" text="Help"> <items> <MenuItem mnemonicParsing="false" text="About" /> </items> </Menu> </menus> <effect> <DropShadow color="#802a40" height="152.82" radius="42.894999999999996" spread="0.6" width="20.76" /> </effect> </MenuBar> </top> </BorderPane>
Ma classe FileBrowser ent trant que InternalFrame sans DektopPane :
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212 package application; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Desktop; import java.awt.Dimension; import java.awt.event.ActionEvent; //import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import javax.swing.JButton; import javax.swing.JFileChooser; //import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; //import javax.swing.UIManager; //import javax.swing.UnsupportedLookAndFeelException; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; //import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel; public class FileBrowser extends javax.swing.JInternalFrame { /** * */ private static final long serialVersionUID = 1L; public void InternalFrame() { initComponents(); } private JInternalFrame frame; private JButton b; private JButton a; private JTree tree; private JProgressBar progress; //private int flag ; //private int flag1 ; public FileBrowser() { frame = new JInternalFrame("Tornado Project Explorer"); progress = new JProgressBar(); progress.setIndeterminate(true); frame.add(progress, BorderLayout.NORTH); progress.setVisible(false); tree = new JTree(new DefaultTreeModel(new DefaultMutableTreeNode("Vide"))); tree.setCellRenderer(new FileTreeCellRenderer()); b = new JButton("View Files Tree Only :No select for read "); a =new JButton("open"); b.addActionListener((ActionEvent arg0) -> { JFileChooser chooser = new JFileChooser(); chooser.setPreferredSize(new Dimension(600, 400)); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int flag = chooser.showDialog(frame, "Choisir répertoire"); //chooser.setPreferredSize(100,50); if(flag == JFileChooser.APPROVE_OPTION) { DirectoryWorker worker = new DirectoryWorker(chooser.getSelectedFile()); // try { // Desktop.getDesktop().open(chooser.getSelectedFile()); //} catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); //} progress.setVisible(true); frame.validate(); worker.execute(); } }); a.addActionListener((ActionEvent arg0) -> { JFileChooser chooser = new JFileChooser(); chooser.setPreferredSize(new Dimension(600, 400)); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int flag = chooser.showDialog(frame, "Open"); if(flag == JFileChooser.APPROVE_OPTION) { DirectoryWorker worker = new DirectoryWorker(chooser.getSelectedFile()); try { Desktop.getDesktop().open(chooser.getSelectedFile()); } catch (IOException e) { // TODO Auto-generated catch block } progress.setVisible(true); frame.validate(); worker.execute(); } }); frame.setSize(340, 680); frame.add(new JScrollPane(tree), BorderLayout.CENTER); frame.add(b, BorderLayout.SOUTH); frame.add(a, BorderLayout.EAST); // frame.setLocationRelativeTo(null); frame.setVisible(true); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public JInternalFrame getFrame() { return frame; } private void initComponents() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } private class FileTreeCellRenderer extends DefaultTreeCellRenderer { /** * */ private static final long serialVersionUID = 1L; /* (non-Javadoc) * @see javax.swing.tree.DefaultTreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean) */ @Override public Component getTreeCellRendererComponent(JTree arg0, Object arg1, boolean arg2, boolean arg3, boolean arg4, int arg5, boolean arg6) { // TODO Module de remplacement de méthode auto-généré super.getTreeCellRendererComponent(arg0, arg1, arg2, arg3, arg4, arg5, arg6); System.out.println(arg1.getClass()); if(DefaultMutableTreeNode.class.equals(arg1.getClass())) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) arg1; if(File.class.equals(node.getUserObject().getClass())) { File f = (File) node.getUserObject(); setText(f.getName()); } } return this; } } private class DirectoryWorker extends SwingWorker<DefaultMutableTreeNode, Void> { private DefaultMutableTreeNode root=null; private final File f; public DirectoryWorker(File f) { super(); this.f = f; } @Override protected DefaultMutableTreeNode doInBackground() throws Exception { root = buildFileTree(f); return null; } @Override protected void done() { tree.setModel(new DefaultTreeModel(root)); progress.setVisible(false); frame.validate(); super.done(); } private DefaultMutableTreeNode buildFileTree(File f) { System.out.println(f.getAbsolutePath()); DefaultMutableTreeNode node = new DefaultMutableTreeNode(f); if(f.isDirectory()) { File[] children = f.listFiles(); for (File child : children) { node.add(buildFileTree(child)); } } return node; } } public static void main(String[] args) { SwingUtilities.invokeLater(() -> { new FileBrowser().getFrame().setVisible(true); }); } }
classe DesktopPane pour le File Browser :
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 package application; //import java.awt.Component; /** * * @author Crypter */ public class desktop extends javax.swing.JFrame { /** * */ private static final long serialVersionUID = 1L; /** * Creates new form desktop */ public desktop() { initComponents(); } private void initComponents() { jDesktopPane1 = new javax.swing.JDesktopPane(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1); jDesktopPane1.setLayout(jDesktopPane1Layout); jDesktopPane1Layout.setHorizontalGroup( jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 575, Short.MAX_VALUE) ); jDesktopPane1Layout.setVerticalGroup( jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 394, Short.MAX_VALUE) ); jButton1.setText("clickme"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jDesktopPane1) .addGroup(layout.createSequentialGroup() .addComponent(jButton1) .addGap(0, 0, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jDesktopPane1) .addGap(18, 18, 18) .addComponent(jButton1)) ); jButton1.getAccessibleContext().setAccessibleName("Clickme"); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { FileBrowser fileBrowser = new FileBrowser(); jDesktopPane1.add( fileBrowser.getFrame() ); // Component add; // TODO add your handling code here: // FileBrowser If; // If = new FileBrowser (); //jDesktopPane1.add(If); //If.show(); jDesktopPane1.add( new FileBrowser() ); } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(desktop.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(desktop.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(desktop.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(desktop.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new desktop().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JDesktopPane jDesktopPane1; // End of variables declaration }
Partager