Je n'arrive pas à afficher mon ScrollPane
C'est bon j'ai trouvé...
Il fallait modifier 2-3 trucs...
Je mets mon code actuel :
Code:
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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
| import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import javax.swing.*;
class SRD1001View extends JFrame {
//private JPanel mainPanel = new JPanel();
private JScrollPane mainPanel = new JScrollPane();
private JMenuBar menu = new JMenuBar();
private JTextArea mesCommandes = new JTextArea();
private JMenu menu1 = new JMenu("File");
private JMenu menu2 = new JMenu("Edit");
private JMenu menu3 = new JMenu("ACL");
private JMenu menu4 = new JMenu("Help");
private JMenuItem menuHelp = new JMenuItem("Help");
private JMenuItem menuDelay = new JMenuItem("Delay");
private JMenuItem menuGetAni = new JMenuItem("GetAni");
private JMenuItem menuGetDgi = new JMenuItem("GetDgi");
private JMenuItem menuGetDgo = new JMenuItem("GetDgo");
private JMenuItem menuGoHome = new JMenuItem("GoHome");
private JMenuItem menuGoPosition = new JMenuItem("GoPosition");
private JMenuItem menuGripperClose = new JMenuItem("GripperClose");
private JMenuItem menuGripperOpen = new JMenuItem("GripperOpen");
private JMenuItem menuIfElse = new JMenuItem("If / Else");
private JMenuItem menuLoopEndloop = new JMenuItem("Loop / Endloop");
private JMenuItem menuSetDgo = new JMenuItem("SetDgo");
private JMenuItem menuCopy = new JMenuItem("Copy");
private JMenuItem menuPaste = new JMenuItem("Paste");
private JMenuItem menuCut = new JMenuItem("Cut");
private JMenuItem menuDeleteAll = new JMenuItem("Delete All");
private JMenuItem menuNew = new JMenuItem("New");
private JMenuItem menuOpen = new JMenuItem("Open");
private JMenuItem menuSave = new JMenuItem("Save");
private JMenuItem menuQuit = new JMenuItem("Quit");
public SRD1001View() {
setTitle("SRD1001");
setSize(400, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
menuSave.addActionListener(new MenuSaveListener());
menuHelp.addActionListener(new MenuHelpListener());
menuNew.addActionListener(new MenuNewListener());
menuCopy.addActionListener(new MenuCopyListener());
menuPaste.addActionListener(new MenuPasteListener());
menuCut.addActionListener(new MenuCutListener());
menuDeleteAll.addActionListener(new MenuDeleteAllListener());
menuQuit.addActionListener(new MenuQuitListener());
menuGoHome.addActionListener(new MenuGoHomeListener());
menuGoPosition.addActionListener(new MenuGoPositionListener());
menuDelay.addActionListener(new MenuDelayListener());
menuGripperClose.addActionListener(new MenuGripperCloseListener());
menuGripperOpen.addActionListener(new MenuGripperOpenListener());
menuLoopEndloop.addActionListener(new MenuLoopEndloopListener());
menuSetDgo.addActionListener(new MenuSetDgoListener());
menuGetDgi.addActionListener(new MenuGetDgiListener());
menuGetDgo.addActionListener(new MenuGetDgoListener());
menuGetAni.addActionListener(new MenuGetAniListener());
menuIfElse.addActionListener(new MenuIfElseListener());
//Configurer les composants (exemple: setText pour un bouton)
mesCommandes.setEditable(false);
//Ajouter les menu1-2-3-4 dans le menuPrincipal
//Ajouter les menuItem dans les menu1-2-3-4
menu.add(menu1);
menu.add(menu2);
menu.add(menu3);
menu.add(menu4);
menu1.add(menuNew);
menu1.add(menuOpen);
menu1.add(menuSave);
menu1.add(menuQuit);
menu2.add(menuCopy);
menu2.add(menuPaste);
menu2.add(menuCut);
menu2.add(menuDeleteAll);
menu3.add(menuDelay);
menu3.add(menuGetAni);
menu3.add(menuGetDgi);
menu3.add(menuGetDgo);
menu3.add(menuGoHome);
menu3.add(menuGoPosition);
menu3.add(menuGripperClose);
menu3.add(menuGripperOpen);
menu3.add(menuIfElse);
menu3.add(menuLoopEndloop);
menu3.add(menuSetDgo);
menu4.add(menuHelp);
mesCommandes.setCaretPosition(0);
//Ajouter les composants dans le panel
mainPanel.add(menu);
mainPanel.add(mesCommandes);
mainPanel.setViewportView(mesCommandes);
//Placer les composants
menu.setBounds(0, 0, 400, 20);
mesCommandes.setBounds(0, 20, 385, 243);
//Placer le panel sur la Frame
setJMenuBar(menu);
add(mainPanel);
}
class MenuHelpListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
help(e);
}
}
class MenuSaveListener implements ActionListener{
public void actionPerformed(ActionEvent e){
save(e);
}
}
class MenuNewListener implements ActionListener{
public void actionPerformed(ActionEvent e){
newFile(e);
}
}
class MenuCopyListener implements ActionListener{
public void actionPerformed(ActionEvent e){
copy(e);
}
}
class MenuPasteListener implements ActionListener{
public void actionPerformed(ActionEvent e){
paste(e);
}
}
class MenuCutListener implements ActionListener{
public void actionPerformed(ActionEvent e){
cut(e);
}
}
class MenuDeleteAllListener implements ActionListener{
public void actionPerformed(ActionEvent e){
deleteAll(e);
}
}
class MenuQuitListener implements ActionListener{
public void actionPerformed(ActionEvent e){
quit(e);
}
}
class MenuGoHomeListener implements ActionListener{
public void actionPerformed(ActionEvent e){
gohome(e);
}
}
class MenuGoPositionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
goposition(e);
}
}
class MenuDelayListener implements ActionListener{
public void actionPerformed(ActionEvent e){
delay(e);
}
}
class MenuGripperCloseListener implements ActionListener{
public void actionPerformed(ActionEvent e){
gripperClose(e);
}
}
class MenuGripperOpenListener implements ActionListener{
public void actionPerformed(ActionEvent e){
gripperOpen(e);
}
}
class MenuLoopEndloopListener implements ActionListener{
public void actionPerformed(ActionEvent e){
loopEndloop(e);
}
}
class MenuSetDgoListener implements ActionListener{
public void actionPerformed(ActionEvent e){
setDgo(e);
}
}
class MenuGetDgiListener implements ActionListener{
public void actionPerformed(ActionEvent e){
getDgi(e);
}
}
class MenuGetDgoListener implements ActionListener{
public void actionPerformed(ActionEvent e){
getDgo(e);
}
}
class MenuGetAniListener implements ActionListener{
public void actionPerformed(ActionEvent e){
getAni(e);
}
}
class MenuIfElseListener implements ActionListener{
public void actionPerformed(ActionEvent e){
ifElse(e);
}
}
private void help(ActionEvent e){
Help fenetreHelp = new Help();
fenetreHelp.setVisible(true);
}
private void save(ActionEvent e){
JFileChooser jfc = new JFileChooser();
int result = jfc.showSaveDialog(this);
if(result == JFileChooser.CANCEL_OPTION) return;
File file = jfc.getSelectedFile();
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.close();
}
catch (Exception ex) {
JOptionPane.showMessageDialog(this,ex.getMessage(),"File Error",JOptionPane.ERROR_MESSAGE);
}
}
private void newFile(ActionEvent e){
SRD1001View SRD1001View2 = new SRD1001View();
SRD1001View2.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
SRD1001View2.setVisible(true);
}
private void copy(ActionEvent e){
mesCommandes.copy();
}
private void paste(ActionEvent e){
mesCommandes.paste();
}
private void cut(ActionEvent e){
mesCommandes.cut();
}
private void deleteAll(ActionEvent e){
mesCommandes.setText("");
}
private void quit(ActionEvent e){
dispose();
}
private void gohome(ActionEvent e){
GoHome fenetreGoHome = new GoHome(this);
fenetreGoHome.setVisible(true);
}
public void setTextGoHome(String text){
mesCommandes.append(text);
}
private void goposition(ActionEvent e){
GoPosition fenetreGoPosition = new GoPosition(this);
fenetreGoPosition.setVisible(true);
}
public void setTextGoPosition(String text){
mesCommandes.append(text);
}
private void delay(ActionEvent e){
Delay fenetreDelay = new Delay(this);
fenetreDelay.setVisible(true);
}
public void setTextDelay(String text){
mesCommandes.append(text);
}
private void gripperClose(ActionEvent e){
mesCommandes.append("GripperClose\n");
}
private void gripperOpen(ActionEvent e){
mesCommandes.append("GripperOpen\n");
}
private void loopEndloop(ActionEvent e){
LoopEndloop fenetreLoopEndloop = new LoopEndloop(this);
fenetreLoopEndloop.setVisible(true);
}
public void setTextLoopEndloop(String text){
mesCommandes.append(text);
}
private void setDgo(ActionEvent e){
SetDgo fenetreSetDgo = new SetDgo(this);
fenetreSetDgo.setVisible(true);
}
public void setTextSetDgo(String text){
mesCommandes.append(text);
}
private void getDgi(ActionEvent e){
GetDgi fenetreGetDgi = new GetDgi(this);
fenetreGetDgi.setVisible(true);
}
public void setTextGetDgi(String text){
mesCommandes.append(text);
}
private void getDgo(ActionEvent e){
GetDgo fenetreGetDgo = new GetDgo(this);
fenetreGetDgo.setVisible(true);
}
public void setTextGetDgo(String text){
mesCommandes.append(text);
}
private void getAni(ActionEvent e){
GetAni fenetreGetAni = new GetAni(this);
fenetreGetAni.setVisible(true);
}
public void setTextGetAni(String text){
mesCommandes.append(text);
}
private void ifElse(ActionEvent e){
IfElse fenetreIfElse = new IfElse(this);
fenetreIfElse.setVisible(true);
}
public void setTextIfElse(String text){
mesCommandes.append(text);
}
} |
Bonjour,
Encore une fois, j'ai un problème avec un ScrollPane.
J'ai essayé de le mettre sur une Frame et rien ne s'affiche.
Je vous mets mon code :
Code:
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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
| import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import javax.swing.*;
class SRD1001View extends JFrame {
//private JPanel mainPanel = new JPanel();
private JScrollPane mainPanel = new JScrollPane();
private JMenuBar menu = new JMenuBar();
private JTextArea mesCommandes = new JTextArea();
private JMenu menu1 = new JMenu("File");
private JMenu menu2 = new JMenu("Edit");
private JMenu menu3 = new JMenu("ACL");
private JMenu menu4 = new JMenu("Help");
private JMenuItem menuHelp = new JMenuItem("Help");
private JMenuItem menuDelay = new JMenuItem("Delay");
private JMenuItem menuGetAni = new JMenuItem("GetAni");
private JMenuItem menuGetDgi = new JMenuItem("GetDgi");
private JMenuItem menuGetDgo = new JMenuItem("GetDgo");
private JMenuItem menuGoHome = new JMenuItem("GoHome");
private JMenuItem menuGoPosition = new JMenuItem("GoPosition");
private JMenuItem menuGripperClose = new JMenuItem("GripperClose");
private JMenuItem menuGripperOpen = new JMenuItem("GripperOpen");
private JMenuItem menuIfElse = new JMenuItem("If / Else");
private JMenuItem menuLoopEndloop = new JMenuItem("Loop / Endloop");
private JMenuItem menuSetDgo = new JMenuItem("SetDgo");
private JMenuItem menuCopy = new JMenuItem("Copy");
private JMenuItem menuPaste = new JMenuItem("Paste");
private JMenuItem menuCut = new JMenuItem("Cut");
private JMenuItem menuDeleteAll = new JMenuItem("Delete All");
private JMenuItem menuNew = new JMenuItem("New");
private JMenuItem menuOpen = new JMenuItem("Open");
private JMenuItem menuSave = new JMenuItem("Save");
private JMenuItem menuQuit = new JMenuItem("Quit");
public SRD1001View() {
setTitle("SRD1001");
setSize(400, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
mainPanel.setLayout(null);
menuSave.addActionListener(new MenuSaveListener());
menuHelp.addActionListener(new MenuHelpListener());
menuNew.addActionListener(new MenuNewListener());
menuCopy.addActionListener(new MenuCopyListener());
menuPaste.addActionListener(new MenuPasteListener());
menuCut.addActionListener(new MenuCutListener());
menuDeleteAll.addActionListener(new MenuDeleteAllListener());
menuQuit.addActionListener(new MenuQuitListener());
menuGoHome.addActionListener(new MenuGoHomeListener());
menuGoPosition.addActionListener(new MenuGoPositionListener());
menuDelay.addActionListener(new MenuDelayListener());
menuGripperClose.addActionListener(new MenuGripperCloseListener());
menuGripperOpen.addActionListener(new MenuGripperOpenListener());
menuLoopEndloop.addActionListener(new MenuLoopEndloopListener());
menuSetDgo.addActionListener(new MenuSetDgoListener());
menuGetDgi.addActionListener(new MenuGetDgiListener());
menuGetDgo.addActionListener(new MenuGetDgoListener());
menuGetAni.addActionListener(new MenuGetAniListener());
menuIfElse.addActionListener(new MenuIfElseListener());
//Configurer les composants (exemple: setText pour un bouton)
mesCommandes.setEditable(false);
//Ajouter les menu1-2-3-4 dans le menuPrincipal
//Ajouter les menuItem dans les menu1-2-3-4
menu.add(menu1);
menu.add(menu2);
menu.add(menu3);
menu.add(menu4);
menu1.add(menuNew);
menu1.add(menuOpen);
menu1.add(menuSave);
menu1.add(menuQuit);
menu2.add(menuCopy);
menu2.add(menuPaste);
menu2.add(menuCut);
menu2.add(menuDeleteAll);
menu3.add(menuDelay);
menu3.add(menuGetAni);
menu3.add(menuGetDgi);
menu3.add(menuGetDgo);
menu3.add(menuGoHome);
menu3.add(menuGoPosition);
menu3.add(menuGripperClose);
menu3.add(menuGripperOpen);
menu3.add(menuIfElse);
menu3.add(menuLoopEndloop);
menu3.add(menuSetDgo);
menu4.add(menuHelp);
mesCommandes.setCaretPosition(0);
//Ajouter les composants dans le panel
mainPanel.add(menu);
mainPanel.add(mesCommandes);
mainPanel.setViewportView(mesCommandes);
//Placer les composants
menu.setBounds(0, 0, 400, 20);
mesCommandes.setBounds(0, 20, 385, 243);
//Placer le panel sur la Frame
this.getContentPane().add(mainPanel);
add(mainPanel);
}
class MenuHelpListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
help(e);
}
}
class MenuSaveListener implements ActionListener{
public void actionPerformed(ActionEvent e){
save(e);
}
}
class MenuNewListener implements ActionListener{
public void actionPerformed(ActionEvent e){
newFile(e);
}
}
class MenuCopyListener implements ActionListener{
public void actionPerformed(ActionEvent e){
copy(e);
}
}
class MenuPasteListener implements ActionListener{
public void actionPerformed(ActionEvent e){
paste(e);
}
}
class MenuCutListener implements ActionListener{
public void actionPerformed(ActionEvent e){
cut(e);
}
}
class MenuDeleteAllListener implements ActionListener{
public void actionPerformed(ActionEvent e){
deleteAll(e);
}
}
class MenuQuitListener implements ActionListener{
public void actionPerformed(ActionEvent e){
quit(e);
}
}
class MenuGoHomeListener implements ActionListener{
public void actionPerformed(ActionEvent e){
gohome(e);
}
}
class MenuGoPositionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
goposition(e);
}
}
class MenuDelayListener implements ActionListener{
public void actionPerformed(ActionEvent e){
delay(e);
}
}
class MenuGripperCloseListener implements ActionListener{
public void actionPerformed(ActionEvent e){
gripperClose(e);
}
}
class MenuGripperOpenListener implements ActionListener{
public void actionPerformed(ActionEvent e){
gripperOpen(e);
}
}
class MenuLoopEndloopListener implements ActionListener{
public void actionPerformed(ActionEvent e){
loopEndloop(e);
}
}
class MenuSetDgoListener implements ActionListener{
public void actionPerformed(ActionEvent e){
setDgo(e);
}
}
class MenuGetDgiListener implements ActionListener{
public void actionPerformed(ActionEvent e){
getDgi(e);
}
}
class MenuGetDgoListener implements ActionListener{
public void actionPerformed(ActionEvent e){
getDgo(e);
}
}
class MenuGetAniListener implements ActionListener{
public void actionPerformed(ActionEvent e){
getAni(e);
}
}
class MenuIfElseListener implements ActionListener{
public void actionPerformed(ActionEvent e){
ifElse(e);
}
}
private void help(ActionEvent e){
Help fenetreHelp = new Help();
fenetreHelp.setVisible(true);
}
private void save(ActionEvent e){
JFileChooser jfc = new JFileChooser();
int result = jfc.showSaveDialog(this);
if(result == JFileChooser.CANCEL_OPTION) return;
File file = jfc.getSelectedFile();
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.close();
}
catch (Exception ex) {
JOptionPane.showMessageDialog(this,ex.getMessage(),"File Error",JOptionPane.ERROR_MESSAGE);
}
}
private void newFile(ActionEvent e){
SRD1001View SRD1001View2 = new SRD1001View();
SRD1001View2.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
SRD1001View2.setVisible(true);
}
private void copy(ActionEvent e){
mesCommandes.copy();
}
private void paste(ActionEvent e){
mesCommandes.paste();
}
private void cut(ActionEvent e){
mesCommandes.cut();
}
private void deleteAll(ActionEvent e){
mesCommandes.setText("");
}
private void quit(ActionEvent e){
dispose();
}
private void gohome(ActionEvent e){
GoHome fenetreGoHome = new GoHome(this);
fenetreGoHome.setVisible(true);
}
public void setTextGoHome(String text){
mesCommandes.append(text);
}
private void goposition(ActionEvent e){
GoPosition fenetreGoPosition = new GoPosition(this);
fenetreGoPosition.setVisible(true);
}
public void setTextGoPosition(String text){
mesCommandes.append(text);
}
private void delay(ActionEvent e){
Delay fenetreDelay = new Delay(this);
fenetreDelay.setVisible(true);
}
public void setTextDelay(String text){
mesCommandes.append(text);
}
private void gripperClose(ActionEvent e){
mesCommandes.append("GripperClose\n");
}
private void gripperOpen(ActionEvent e){
mesCommandes.append("GripperOpen\n");
}
private void loopEndloop(ActionEvent e){
LoopEndloop fenetreLoopEndloop = new LoopEndloop(this);
fenetreLoopEndloop.setVisible(true);
}
public void setTextLoopEndloop(String text){
mesCommandes.append(text);
}
private void setDgo(ActionEvent e){
SetDgo fenetreSetDgo = new SetDgo(this);
fenetreSetDgo.setVisible(true);
}
public void setTextSetDgo(String text){
mesCommandes.append(text);
}
private void getDgi(ActionEvent e){
GetDgi fenetreGetDgi = new GetDgi(this);
fenetreGetDgi.setVisible(true);
}
public void setTextGetDgi(String text){
mesCommandes.append(text);
}
private void getDgo(ActionEvent e){
GetDgo fenetreGetDgo = new GetDgo(this);
fenetreGetDgo.setVisible(true);
}
public void setTextGetDgo(String text){
mesCommandes.append(text);
}
private void getAni(ActionEvent e){
GetAni fenetreGetAni = new GetAni(this);
fenetreGetAni.setVisible(true);
}
public void setTextGetAni(String text){
mesCommandes.append(text);
}
private void ifElse(ActionEvent e){
IfElse fenetreIfElse = new IfElse(this);
fenetreIfElse.setVisible(true);
}
public void setTextIfElse(String text){
mesCommandes.append(text);
}
} |
Merci d'avance