IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AWT/Swing Java Discussion :

Ajout d'un extend JInternalFrame


Sujet :

AWT/Swing Java

  1. #1
    Membre averti Avatar de ImBehoRE
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2018
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : Polynésie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2018
    Messages : 23
    Par défaut Ajout d'un extend JInternalFrame
    Bonjour,

    Je débute en java et je suis paumé depuis un bon moment...
    Pour présenté le contexte, j'ai deux classe :
    1. Une JFrameForm pour faire ma fênetre avec des 2JPanel et une InternalFrame
      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
      public class TestPanel extends JFrame {
       
       
       
          public TestPanel() {
              initComponents();
          }
       
          /**
           * This method is called from within the constructor to initialize the form.
           * WARNING: Do NOT modify this code. The content of this method is always
           * regenerated by the Form Editor.
           */
          @SuppressWarnings("unchecked")
          // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
          private void initComponents() {
       
              jTabbedPane1 = new javax.swing.JTabbedPane();
              PanelCon = new javax.swing.JPanel();
              jButton1 = new javax.swing.JButton();
              jButton2 = new javax.swing.JButton();
              PanelMenu = new javax.swing.JPanel();
              jLabel1 = new javax.swing.JLabel();
              MainWindowCal = new javax.swing.JInternalFrame();
       
              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
       
              jButton1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
              jButton1.setText("Ici bouton");
       
              jButton2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
              jButton2.setText("Encore lui");
       
              javax.swing.GroupLayout PanelConLayout = new javax.swing.GroupLayout(PanelCon);
              PanelCon.setLayout(PanelConLayout);
              PanelConLayout.setHorizontalGroup(
                  PanelConLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelConLayout.createSequentialGroup()
                      .addContainerGap(33, Short.MAX_VALUE)
                      .addGroup(PanelConLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                          .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                          .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                      .addGap(33, 33, 33))
              );
              PanelConLayout.setVerticalGroup(
                  PanelConLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(PanelConLayout.createSequentialGroup()
                      .addGap(40, 40, 40)
                      .addComponent(jButton1)
                      .addGap(18, 18, 18)
                      .addComponent(jButton2)
                      .addContainerGap(385, Short.MAX_VALUE))
              );
       
              jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
              jLabel1.setForeground(new java.awt.Color(0, 153, 153));
              jLabel1.setText("Ici le titre ");
       
              javax.swing.GroupLayout PanelMenuLayout = new javax.swing.GroupLayout(PanelMenu);
              PanelMenu.setLayout(PanelMenuLayout);
              PanelMenuLayout.setHorizontalGroup(
                  PanelMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(PanelMenuLayout.createSequentialGroup()
                      .addGap(30, 30, 30)
                      .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              PanelMenuLayout.setVerticalGroup(
                  PanelMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(PanelMenuLayout.createSequentialGroup()
                      .addGap(25, 25, 25)
                      .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addContainerGap(18, Short.MAX_VALUE))
              );
       
              MainWindowCal.setVisible(true);
       
              javax.swing.GroupLayout MainWindowCalLayout = new javax.swing.GroupLayout(MainWindowCal.getContentPane());
              MainWindowCal.getContentPane().setLayout(MainWindowCalLayout);
              MainWindowCalLayout.setHorizontalGroup(
                  MainWindowCalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGap(0, 767, Short.MAX_VALUE)
              );
              MainWindowCalLayout.setVerticalGroup(
                  MainWindowCalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGap(0, 459, Short.MAX_VALUE)
              );
       
              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                          .addComponent(PanelMenu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                          .addGroup(layout.createSequentialGroup()
                              .addGap(4, 4, 4)
                              .addComponent(MainWindowCal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(PanelCon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                      .addContainerGap())
              );
              layout.setVerticalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                      .addContainerGap()
                      .addComponent(PanelMenu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                          .addGroup(layout.createSequentialGroup()
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(PanelCon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                          .addGroup(layout.createSequentialGroup()
                              .addGap(26, 26, 26)
                              .addComponent(MainWindowCal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                      .addContainerGap())
              );
       
              pack();
          }// </editor-fold>                        
       
       
          /**
           * @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(TestPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              } catch (InstantiationException ex) {
                  java.util.logging.Logger.getLogger(TestPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              } catch (IllegalAccessException ex) {
                  java.util.logging.Logger.getLogger(TestPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                  java.util.logging.Logger.getLogger(TestPanel.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 TestPanel().setVisible(true);
                  }
              });
          }
       
          // Variables declaration - do not modify                     
          private javax.swing.JInternalFrame MainWindowCal;
          private javax.swing.JPanel PanelCon;
          private javax.swing.JPanel PanelMenu;
          private javax.swing.JButton jButton1;
          private javax.swing.JButton jButton2;
          private javax.swing.JLabel jLabel1;
          private javax.swing.JTabbedPane jTabbedPane1;
          // End of variables declaration                   
      }
    2. et une autre classe Java extends JInternalFrame

    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
    public class MainWindowCal extends JInternalFrame
    {
    	public static void main(String[] args)
    	{
    		SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				MainWindowCal window = null;
    				try {
    					window = new MainWindowCal();
    					window.setVisible(true);
    				}
    				catch (Exception exp) {
     
    				}
    			}
    		});
    	}
     
    	public MainWindowCal()
    	{
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setTitle("MindFusion.Scheduling Sample: Minimal Application");
     
    		calendar = new Calendar();
    		calendar.setTheme(ThemeType.Light);
     
    		JToolBar toolBar = new JToolBar();
    		toolBar.setFloatable(false);
     
    		nextButtonInToolbar(toolBar, imageFileNames[0]).addActionListener(new ActionListener(){
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				calendar.setCurrentView(CalendarView.SingleMonth);
    			}
    		});
     
    		nextButtonInToolbar(toolBar, imageFileNames[1]).addActionListener(new ActionListener(){
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				calendar.setCurrentView(CalendarView.MonthRange);
    			}
    		});
     
    		nextButtonInToolbar(toolBar, imageFileNames[2]).addActionListener(new ActionListener(){
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				calendar.setCurrentView(CalendarView.List);
    			}
    		});
     
    		nextButtonInToolbar(toolBar, imageFileNames[3]).addActionListener(new ActionListener(){
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				calendar.setCurrentView(CalendarView.WeekRange);
    			}
    		});
     
    		nextButtonInToolbar(toolBar, imageFileNames[4]).addActionListener(new ActionListener(){
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				calendar.setCurrentView(CalendarView.Timetable);
    			}
    		});
     
     
     
    		Container cp = getContentPane();
    		cp.setLayout(new BorderLayout());
    		cp.add(toolBar, BorderLayout.PAGE_START);
            cp.add(calendar, BorderLayout.CENTER);
     
     
     
            // Initialiser le fichier de date
            _dataFile = new java.io.File("Schedule.dat").getAbsolutePath();
    	}
     
    	private void onWindowOpened() {
    		if (new java.io.File(_dataFile).exists())
    			calendar.getSchedule().loadFrom(_dataFile, ContentType.Xml);
    	}
     
    	private void exit() {
    		calendar.getSchedule().saveTo(_dataFile, ContentType.Xml);
    	}
     
    	private JButton nextButtonInToolbar(JToolBar bar, String imageName)
    	{
    		JButton button = new JButton(new ThumbnailAction(imagedir, imageName));
    		button.setBorderPainted(false);
    		button.setMargin(new Insets(5, 5, 5, 5));
    		button.setSize(35, 35);
     
    		bar.add(button);
     
    		return button;
    	}
        /*
         * Liste de toutes les images à charger.
         */
        private String[] imageFileNames = { "0.png", "1.png", "2.png", "3.png", "4.png", "5.png"};
     
        private String _dataFile;
    	private Calendar calendar;
    	private String imagedir = "Resources/";
    	private static final long serialVersionUID = 1L;
    }
     
    class ThumbnailAction extends AbstractAction
    {
    	public ThumbnailAction(String path, String imagePath)
    	{
    		// LARGE_ICON_KEY est la clé permettant de définir l'icône lorsqu'une action est appliquée à un bouton.
    		ImageIcon icon = createImageIcon(path, imagePath);
    		putValue(LARGE_ICON_KEY, icon);
    	}
     
    	private ImageIcon createImageIcon(String path, String fileName) {
            java.net.URL imgURL = getClass().getResource(path + fileName);
            if (imgURL == null)
            	imgURL = getClass().getResource("/" + path + fileName);
     
            if (imgURL != null) {
                return new ImageIcon(imgURL, fileName);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
            }
        }
     
    	@Override
    	public void actionPerformed(ActionEvent e) {
    	}
     
    	private static final long serialVersionUID = 1L;
    }
    J'obtiens ceci lorsque je change l'extends de ma class MainWindowCal extends JInternalFrame en "extends JFrame"
    Nom : MonCal.JPG
Affichages : 224
Taille : 43,0 Ko

    Et ce que je voudrait, c'est qu'elle s'affiche ici :
    Nom : MonJFrame.JPG
Affichages : 206
Taille : 49,1 Ko

    Mais je ne sais pas comment m'y prendre si quelqu'un peut m'orienter vers une solution, ou bien m'aider.
    Je tien à rappeler que ma class TestPanel extends JFrame ce voit généré automatiquement car j'utilise JFrameForm pour celui-ci.

    Merci pour ceux qui voudront bien m'aider.

  2. #2
    Membre averti Avatar de ImBehoRE
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2018
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : Polynésie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2018
    Messages : 23
    Par défaut
    J'ai résolue mon pb,
    Ma démarche :
    à la place d'un JInternalFrame dans ma class TestPanel, j'ai mis un DeskteopPane :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    DeskCal = new JDesktopPane(); 
    MainWindowCal LeCal = new MainWindowCal();
    DeskCal.add(LeCal);
    LeCal.setVisible(true);
    Et enfin ça marche
    Le résultat :
    Nom : EnfinLeTestEstFini.JPG
Affichages : 206
Taille : 57,0 Ko

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 02/05/2018, 11h13
  2. ajouter un JScrollPane à une JInternalFrame
    Par dydo01 dans le forum Agents de placement/Fenêtres
    Réponses: 6
    Dernier message: 29/06/2010, 14h42
  3. Comment ajouter une icone à une JInternalFrame
    Par wassimb dans le forum AWT/Swing
    Réponses: 11
    Dernier message: 12/07/2006, 15h13
  4. [ SWING ] ajout de JInternalFrame
    Par Invité dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 12/02/2006, 15h50
  5. Ajouter une aide
    Par Mailgifson dans le forum C++Builder
    Réponses: 5
    Dernier message: 12/06/2002, 13h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo