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 :

Positionnement JButton dans panneau


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif

    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Billets dans le blog
    1
    Par défaut Positionnement JButton dans panneau
    Bonjour
    Mon problème est :
    après avoir créer mon interface
    qui contient 5 champs a remplier
    1ere = name panneau
    2eme=ligne "nombre de ligne"
    3eme=colonne 'nombre de colonne"
    4eme=largeur
    5eme=hauteur
    c'est bien fait j'ai un panneau avec le nombre de ligne et colonne saisie et de largeur et hauteur bien fait aussi (panneau remplier avec des button)
    maintenant une fois je Click sur un des button je peux charger un image et le mettre dans un button
    ca c fait auusi
    ensuite ou se trouver le problème je veux utiliser gridx et gridy pour savoir l'emplacement des button pour que je peux mettre ces corrdonnées dans un fichier xml
    le fichier xml et creer lors de la creation panneau
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     <Keypad Name="5" Row="5" Columns="5" X="610" Y="172" Width="5" Height="5">
          <Keys>
            <Key Row="0" Column="0" Image="" Command="" Arg0="" Arg1="Speak" />
            <Key Row="0" Column="1" Image="" Command="" Arg0="" Arg1="Speak" />
            <Key Row="0" Column="2" Image="" Command="" Arg0="" Arg1="Speak" />
    comment je remplier les buuton
    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
    if(ae.getSource()instanceof JButton) 
    {
           //((JButton)ae.getSource()).setBackground(Color.red);
     
               JFileChooser fileChooser = new JFileChooser();
                int returnValue = fileChooser.showOpenDialog(null);
                if (returnValue == JFileChooser.APPROVE_OPTION) {
               try {
                   java.io.File file = fileChooser.getSelectedFile();
                  image = ImageIO.read(file);
                   ImageIcon icon;
                    float width=image.getWidth();
                    float height=image.getHeight();
                    //Determine how the image has to be scaled if it is large:
                    if(image.getHeight()>500 && (width/height)>1){
                        Image thumb = image.getScaledInstance(-1, 100, Image.SCALE_SMOOTH);
                        icon=new ImageIcon(thumb);
                    }
                    else if(image.getHeight() > 500 && (width / height) <= 1)
                    {
                        Image thumb = image.getScaledInstance(100, -1, Image.SCALE_SMOOTH);
                        icon=new ImageIcon(thumb);
                    }
                    else {icon = new ImageIcon(image);}
                      ((JButton)ae.getSource()).setIcon(icon);
    Merci

  2. #2
    Membre actif

    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Billets dans le blog
    1
    Par défaut
    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
    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
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package Sibylle.tableauPico;
     
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.GridLayout;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Locale;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JPopupMenu;
    import javax.swing.event.AncestorListener;
    import org.jdom2.Attribute;
    import org.jdom2.Document;
    import org.jdom2.Element;
    import org.jdom2.input.SAXBuilder;
    import org.jdom2.output.Format;
    import org.jdom2.output.XMLOutputter;
     
    /**
     *
     * @author SAMSUNG
     */
    public class configPicto extends javax.swing.JFrame implements ActionListener, ItemListener {
    BufferedImage image1,image;
    int i,j,g,h;
    String k;
      static Element racine = new Element("Keybord");
    static org.jdom2.Document document = new Document(racine);
    JButton[][] btnz = new JButton[100][100];
        /**
         * Creates new form configPicto
         */
        public configPicto() {
            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() {
     
            jPanel2 = new javax.swing.JPanel();
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jLabel5 = new javax.swing.JLabel();
            name = new javax.swing.JTextField();
            colonne = new javax.swing.JTextField();
            Hauteur = new javax.swing.JTextField();
            Largeur = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();
            ligne = new javax.swing.JTextField();
     
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jLabel1.setText("Nom Tableau :");
     
            jLabel2.setText("Ligne             :");
     
            jLabel3.setText("Colonne        : ");
     
            jLabel4.setText("Hauteur        :");
     
            jLabel5.setText("Largeur        :");
     
            jButton1.setText("ok");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(25, 25, 25)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGap(52, 52, 52)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(ligne, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGap(55, 55, 55)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(Hauteur, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                                        .addComponent(colonne)
                                        .addComponent(Largeur)))))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(147, 147, 147)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(115, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(16, 16, 16)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(ligne, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(26, 26, 26)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(colonne, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(21, 21, 21)
                            .addComponent(jLabel4))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(14, 14, 14)
                            .addComponent(Hauteur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(Largeur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel5))))
                    .addGap(77, 77, 77)
                    .addComponent(jButton1)
                    .addContainerGap(33, Short.MAX_VALUE))
            );
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE))
            );
     
            pack();
        }// </editor-fold>                        
     
    public JButton button(int i,int j){
        JButton button=new JButton();
        button.setPreferredSize(new Dimension(i, j));
        return button;
     
    }
     final JPopupMenu popupMenu = new JPopupMenu();
      GridBagConstraints c = new GridBagConstraints();
    public JPanel panel(Integer ligne,Integer colonne) throws IOException  {
        JPanel panel=new JPanel();
         panel.setOpaque(true);
            // PanelAlphabet.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            panel.setLayout(new GridBagLayout());
     
         for(Integer i=0;i<ligne;i++)
            {
                for(Integer j=0;j<colonne;j++)
                {
     
                    btnz[i][j]= new JButton("");
     
                  //  btnz[i][j].setBackground(Color.WHITE);
                 //  btnz[i][j].setBounds(10+20*i,10+20*j,20,20);
                   //btnz[i][j].setPreferredSize(new Dimension(t1, t2));
                    btnz[i][j].setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
                            File file=new File("Image/add.png");
                            image1=ImageIO.read(file); 
                             file=new File("Image/add.png");
                               image=ImageIO.read(file);
            //btnz[i][j].setComponentPopupMenu(popupMenu);
                    ImageIcon icon;
                    float width=image.getWidth();
                    float height=image.getHeight();
     
                    //Determine how the image has to be scaled if it is large:
                    if(image.getHeight()>500 && (width/height)>1){
                        Image thumb = image.getScaledInstance(-1, Image.SCALE_SMOOTH, Image.SCALE_SMOOTH);
                        icon=new ImageIcon(thumb);
                    }
                    else if(image.getHeight() > 500 && (width / height) <= 1)
                    {
                        Image thumb = image.getScaledInstance(Image.SCALE_SMOOTH, -1, Image.SCALE_SMOOTH);
                        icon=new ImageIcon(thumb);
                    }
                    else {icon = new ImageIcon(image);}
     
               btnz[i][j].setIcon(icon);
                btnz[i][j].setText("");
                  c.gridx=i;
                    c.gridy=j;
                    c.gridheight=1;
                    c.gridwidth=1;
                    c.weightx=1;
                    c.weighty=1;
     btnz[i][j].addActionListener(this);  
     
     panel.add( btnz[i][j],c);   
                }
     
            } 
     
         JMenuItem cutMenuItem = new JMenuItem("Modifier");
        cutMenuItem.addActionListener(this);
        popupMenu.add(cutMenuItem);
     
        // *******
        JMenuItem copyMenuItem = new JMenuItem("Supprimer");
        copyMenuItem.addActionListener(this);
        popupMenu.add(copyMenuItem);
     
        panel.setLayout(new GridLayout(ligne,colonne));
        return panel;
     
    }
    public  void changer(String adresse){
         Element Keypads = new Element("Keypads");
          racine.addContent(Keypads);
          Element Keypad = new Element("Keypad");
          Keypads.addContent(Keypad);
          Attribute Name  = new Attribute("Name",Name());
          Keypad.setAttribute(Name);
          Attribute Rows=new Attribute("Row",ligne());
          Keypad.setAttribute(Rows);
          Attribute Columns=new Attribute("Columns", colonne());
          Keypad.setAttribute(Columns);
          Attribute X=new Attribute("X", "610");
          Keypad.setAttribute(X);
          Attribute Y=new Attribute("Y", "172");
          Keypad.setAttribute(Y);
          Attribute Width=new Attribute("Width", largeur());
          Keypad.setAttribute(Width);
          Attribute Height=new Attribute("Height", hauteur());
          Keypad.setAttribute(Height);
           Element Keys = new Element("Keys");
           Keypad.addContent(Keys);
           String rows=Keypad.getAttributeValue("Row");
           String columns=Keypad.getAttributeValue("Columns");
           Integer ligne = Integer.valueOf(rows);
           Integer colonne = Integer.valueOf(columns);
           for(int i=0;i<ligne;i++){
               for(int j=0;j<ligne;j++){
              Element Key = new Element("Key");
            Keys.addContent(Key);
            Attribute Row  = new Attribute("Row",""+i);
            Key.setAttribute(Row);
            Attribute Column = new Attribute("Column",""+j);
            Key.setAttribute(Column);
            Attribute Image = new Attribute("Image",""+adresse);
            Key.setAttribute(Image);
            Attribute Command = new Attribute("Command","GotoKeypad");
            Key.setAttribute(Command);
            Attribute Arg0 = new Attribute("Arg0","");
            Key.setAttribute(Arg0);
            Attribute Arg1 = new Attribute("Arg1","Speak");
            Key.setAttribute(Arg1);
     
    }}}
    static void enregistreFichier(String fichier) throws Exception
       {
             XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
             sortie.output(document, new FileOutputStream(fichier));
     
     
       }
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     
          JFrame fen = new JFrame();
          i= Integer.parseInt(hauteur());
          j= Integer.parseInt(largeur());
          g=Integer.parseInt(ligne());
          h=Integer.parseInt(colonne());
          k=Name();
     
          fen.setTitle(k);
          fen.setSize(i ,j);  
         barreMenus = new JMenuBar() ;
    setJMenuBar(barreMenus) ;
    fichier = new JMenu ("fichier") ;
    barreMenus.add(fichier) ;
    enregister = new JMenuItem ("Enregistrer") ;
    fichier.add(enregister) ;
    enregister.addActionListener (this) ;
    fen.setJMenuBar(barreMenus);
         changer("");
        try {
            enregistreFichier("c:/XML_résultat.xml");
        } catch (Exception ex) {
            Logger.getLogger(configPicto.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            fen.add(panel( g, h));
        } catch (IOException ex) {
            Logger.getLogger(configPicto.class.getName()).log(Level.SEVERE, null, ex);
        }
     
     
          this.dispose();  
          fen.setVisible(true);  // TODO add your handling code here:
        }                                        
        private JMenuBar barreMenus ;
    private JMenu fichier, dimensions ;
    private JMenuItem enregister;
        /**
         * @param args the command line arguments
         */public String Name(){
         String chaine;
        chaine=name.getText();
        return chaine;
    }
        public String ligne(){
        String chaine;
        chaine=ligne.getText();
        return chaine;
    }
    public String colonne(){
        String chaine;
        chaine=colonne.getText();
        return chaine;
    }
    public String hauteur(){
        String chaine;
        chaine=Hauteur.getText();
        return chaine;
    }
    public String largeur(){
        String chaine;
        chaine=Largeur.getText();
        return chaine;
    }
        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(configPicto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(configPicto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(configPicto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(configPicto.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 configPicto().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify                     
        private javax.swing.JTextField Hauteur;
        private javax.swing.JTextField Largeur;
        private javax.swing.JTextField colonne;
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JTextField ligne;
        private javax.swing.JTextField name;
        // End of variables declaration                   
     static void lireFichier(String fichier) throws Exception
       {
          SAXBuilder sxb = new SAXBuilder();
          document = sxb.build(new File(fichier));
          racine = document.getRootElement();
       }
        @Override
        public void actionPerformed(ActionEvent ae) {
             Object source = ae.getSource() ;
       if (source==enregister)
     
          try {
               JFileChooser fileChooser = new JFileChooser();
                int returnValue = fileChooser.showSaveDialog(null);
                if (returnValue == JFileChooser.APPROVE_OPTION) {
                    File file = fileChooser.getSelectedFile();
     
                       XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
                       sortie.output(document, new FileOutputStream(file));
                 }} catch (Exception ex) {
                } 
     
     if(ae.getSource()instanceof JButton) 
    {
           //((JButton)ae.getSource()).setBackground(Color.red);
     
               JFileChooser fileChooser = new JFileChooser();
                int returnValue = fileChooser.showOpenDialog(null);
                if (returnValue == JFileChooser.APPROVE_OPTION) {
               try {
                   java.io.File file = fileChooser.getSelectedFile();
                  image = ImageIO.read(file);
                   ImageIcon icon;
                    float width=image.getWidth();
                    float height=image.getHeight();
                    //Determine how the image has to be scaled if it is large:
                    if(image.getHeight()>500 && (width/height)>1){
                        Image thumb = image.getScaledInstance(-1, 100, Image.SCALE_SMOOTH);
                        icon=new ImageIcon(thumb);
                    }
                    else if(image.getHeight() > 500 && (width / height) <= 1)
                    {
                        Image thumb = image.getScaledInstance(100, -1, Image.SCALE_SMOOTH);
                        icon=new ImageIcon(thumb);
                    }
                    else {icon = new ImageIcon(image);}
                      ((JButton)ae.getSource()).setIcon(icon);
     
     
     
             /*
                Image thumb=image.getScaledInstance(50, -1,50); 
                ImageIcon icon=new ImageIcon(thumb); 
                ((JButton)ae.getSource()).setSize(new Dimension(14,14));
                ((JButton)ae.getSource()).setIcon(icon);*/
     
               } catch (IOException ex) {
                   Logger.getLogger(configPicto.class.getName()).log(Level.SEVERE, null, ex);
               } catch (Exception ex) {
                   Logger.getLogger(configPicto.class.getName()).log(Level.SEVERE, null, ex);
               }
    	}
     
    } 
     
     
     
     
     
        }
     
        @Override
        public void itemStateChanged(ItemEvent ie) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }

Discussions similaires

  1. Positionnement d'un JButton dans un GridLayout
    Par adissa357 dans le forum Agents de placement/Fenêtres
    Réponses: 10
    Dernier message: 11/11/2013, 01h28
  2. Positionnement d'un JButton dans un JPanel
    Par Eausport dans le forum Agents de placement/Fenêtres
    Réponses: 5
    Dernier message: 25/05/2012, 11h32
  3. Dossier Système dans panneau configuration
    Par majo07 dans le forum Autres Logiciels
    Réponses: 3
    Dernier message: 20/12/2005, 10h40
  4. Pb JButton dans un JLabel
    Par Ecco59 dans le forum Composants
    Réponses: 8
    Dernier message: 02/12/2005, 18h09
  5. [JTable] Un JButton dans une cellule
    Par Sarrus dans le forum Composants
    Réponses: 19
    Dernier message: 31/08/2005, 16h29

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