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

Agents de placement/Fenêtres Java Discussion :

[JScrollPane] Positionnement du scrollpane


Sujet :

Agents de placement/Fenêtres Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé Avatar de soulhouf
    Inscrit en
    Août 2005
    Messages
    213
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 213
    Par défaut [JScrollPane] Positionnement du scrollpane
    bonjour,

    j'ai une classe TabbedStore (qui hérite de JTabbedPane) qui se compose de 2 objets de la classe StoreTable (qui hérite de JTable).
    mon problème est le suivant:
    je n'arrive pas à associer un scroll pane aux 2 tables qui composent mon tabbed pane.
    je vous associe le code pour que vous puissez l'executer chez vous:
    TabbedStore.java
    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
     
    import java.awt.Dimension;
    import java.awt.event.KeyEvent;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
     
    public class TabbedStore extends JTabbedPane {
        // ------------------------------------------------------------------------
        // Elements declaration of the Store Component
        // ------------------------------------------------------------------------   
        private StoreTable personnalTable;
        private StoreTable otherPersonsTable;
     
        public TabbedStore(Language lang, Object[][] data1, Object[][] data2) {
            super();
            personnalTable = new StoreTable(lang, data1);
            personnalTable.setPreferredSize(new Dimension(400, 110));
            //Create the scroll pane and add the table to it.        
            JScrollPane scrollPane1 = new JScrollPane(personnalTable); //là est le problème
            //Add the scroll pane to this panel.
            add(scrollPane1);
     
            otherPersonsTable = new StoreTable(lang, data2);
            otherPersonsTable.setPreferredSize(new Dimension(400, 110));
            //Create the scroll pane and add the table to it.       
            JScrollPane scrollPane2 = new JScrollPane(otherPersonsTable);//là est le problème
            //Add the scroll pane to this panel.
            add(scrollPane2);
     
            String[] titles = lang.getCertifStoreTitle();
     
            this.addTab(titles[0], personnalTable);
            this.setMnemonicAt(0, KeyEvent.VK_1);
     
            this.addTab(titles[1], otherPersonsTable);
            this.setMnemonicAt(1, KeyEvent.VK_2);
        }
     
     
    }
    StoreTable.java
    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
     
    import java.awt.Dimension;
    import javax.swing.JTable;
    import MainInterface.observant.Observant;
     
    public class StoreTable extends JTable{
        // ------------------------------------------------------------------------
        // Elements declaration of the Store Component
        // ------------------------------------------------------------------------
        // objects to put in the table
        private Object[][] data;
     
        public StoreTable(Language lang, Object[][] data){
     
            super(data, lang.getTableHeaders());
            super.setPreferredScrollableViewportSize(new Dimension(400, 110));
     
            this.data = data;
        }
    }
    Language.java
    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
     
     
    public class Language {
     
        private String language;
     
        public Language(String language) {
            this.language = language;
        }
     
        public String[] getTableHeaders(){
            String[] th = new String[3];
            if(language.equalsIgnoreCase("french")){
                th[0] = "Délivré à";
                th[1] = "Délivré par";
                th[2] = "Date d'expiration";
            }else{
                if(language.equalsIgnoreCase("english")){
                    th[0] = "Delivred in";
                    th[1] = "Delivred by";
                    th[2] = "Scratch date";
                }
            }
            return th;
        }
     
        public String[] getCertifStoreTitle(){
            String[] th = new String[2];
            if(language.equalsIgnoreCase("french")){
                th[0] = "Personnel";
                th[1] = "Autres personnes";
            }else{
                if(language.equalsIgnoreCase("english")){
                    th[0] = "Personnal";
                    th[1] = "Other persons";
                }
            }
            return th;
        }
     
        public String getButtonOKTitle(){       
                return "OK";
        }
     
        public String getButtonCancelTitle(){       
            if(language.equalsIgnoreCase("french")){
                return "Annuler";
            }else{
                if(language.equalsIgnoreCase("english")){
                    return "Cancel";
                }
            }
            return null;
        }
     
    }
    et voici la classe de test qui appelle tout ça:
    InterfaceTest2.java
    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
     
     
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
     
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
    public class InterfaceTest2 extends JPanel {
        private boolean DEBUG = false;
     
        public InterfaceTest2() {
            super(new GridLayout(1,1));
            Object[][] data = {
                {"Mary", "Campione",
                 "Snowboarding"},
                {"Alison", "Huml",
                 "Rowing"},
                {"Kathy", "Walrath",
                 "Knitting"},
                {"Sharon", "Zakhour",
                 "Speed reading"},
                {"Philip", "Milne",
                 "Pool"}
            };
     
            Language lang = new Language("french");
     
            TabbedStore tabbedPane = new TabbedStore(lang, data, data);
            //add the tabbed store
            add(tabbedPane);
        }
     
        protected JComponent makeTextPanel(String text) {
            JPanel panel = new JPanel(false);
            JLabel filler = new JLabel(text);
            filler.setHorizontalAlignment(JLabel.CENTER);
            panel.setLayout(new GridLayout(1, 1));
            panel.add(filler);
            return panel;
        }
     
        /**
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         */
        private static void createAndShowGUI() {
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
     
            //Create and set up the window.
            JFrame frame = new JFrame("TabbedStoreDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            //Create and set up the content pane.
            JComponent newContentPane = new InterfaceTest2();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.getContentPane().add(new InterfaceTest2(),
                                     BorderLayout.CENTER);
     
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        }
     
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }
    voilà s'il manque un truc signalez le moi car mon projet contient beaucoup plus que ça et j'ai arraché ces classes sans vérifier si elles fonctionnent toutes seules.

    en plus il y a un autre problème: il me crée 4 onglets alors que je n'ai demandé que 2.

    merci d'avance

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    154
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 154
    Par défaut
    J'ai pas tous lu mais je sais pour les 4 tabs : tu appelles 2 * add et 2 * addTab. Ces deux méthodes permettent d'ajouter un nouvel onglet au tabbedpane. Pour les tabbedpane, il faut préférer addTab.
    Je penses que ceci marcherait mieux :
    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
    import java.awt.Dimension;
    import java.awt.event.KeyEvent;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
     
    public class TabbedStore extends JTabbedPane {
        // ------------------------------------------------------------------------
        // Elements declaration of the Store Component
        // ------------------------------------------------------------------------   
        private StoreTable personnalTable;
        private StoreTable otherPersonsTable;
     
        public TabbedStore(Language lang, Object[][] data1, Object[][] data2) {
            super();
            personnalTable = new StoreTable(lang, data1);
            personnalTable.setPreferredSize(new Dimension(400, 110));
            //Create the scroll pane and add the table to it.       
            JScrollPane scrollPane1 = new JScrollPane(personnalTable); //là est le problème
            //Add the scroll pane to this panel.
          //  add(scrollPane1); pas bien
     
            otherPersonsTable = new StoreTable(lang, data2);
            otherPersonsTable.setPreferredSize(new Dimension(400, 110));
            //Create the scroll pane and add the table to it.       
            JScrollPane scrollPane2 = new JScrollPane(otherPersonsTable);//là est le problème
            //Add the scroll pane to this panel.
           // add(scrollPane2); pas bien
     
            String[] titles = lang.getCertifStoreTitle();
     
            this.addTab(titles[0], scrollPane1 /*personnalTable*/);
            this.setMnemonicAt(0, KeyEvent.VK_1);
     
            this.addTab(titles[1], scrollPane2 /*otherPersonsTable*/);
            this.setMnemonicAt(1, KeyEvent.VK_2);
        }
     
     
    }

  3. #3
    Membre confirmé Avatar de soulhouf
    Inscrit en
    Août 2005
    Messages
    213
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 213
    Par défaut
    merci bien ça marche à merveille maintenant!
    sinon j'ai une autre question: si je veux ajouter des boutons de petite taille comment je fais?
    j'ai essayé la methode setMaximumSize(Dimension d) de JComponent mais ça marche pas, il fait toujours à sa tête

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

Discussions similaires

  1. Problème de positionnement de JScrollBar dans une JScrollPane
    Par Gandalf2008 dans le forum Agents de placement/Fenêtres
    Réponses: 5
    Dernier message: 02/06/2008, 16h10
  2. [JScrollPane] Positionnement du scrollpane
    Par Chewbacce dans le forum Composants
    Réponses: 4
    Dernier message: 19/05/2008, 22h44
  3. Réponses: 1
    Dernier message: 17/05/2007, 11h54
  4. [JScrollPane] positionnement des scrollbars
    Par Dnasty dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 19/03/2006, 15h46
  5. [Jtree][JScrollPane] problème de positionnement
    Par billynirvana dans le forum Agents de placement/Fenêtres
    Réponses: 2
    Dernier message: 07/07/2005, 17h53

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