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

Interfaces Graphiques en Java Discussion :

Problèmes avec ScrollBar


Sujet :

Interfaces Graphiques en Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2011
    Messages : 1
    Par défaut Problèmes avec ScrollBar
    Bonjour!
    Nous voulons, développer un programme baser sur l'interprétation de signal midi........
    Enfin bref nous en sommes au début et nous rencontrer quelques problèmes, notament dans l'interface graphique: nous voudrions faire apparaître une scrollbar verticale et une horizontale. Cependant toute nos tentatives ont échoué(nous n'arrivons pas a avoir les ascenseurs) . Pouvez vous nous aider?


    voici le code


    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
     
    import java.awt.*;
    import java.awt.event.*;
     
     
    import javax.swing.*;
    import javax.swing.JScrollPane;
    import java.awt.Graphics2D;
    import java.awt.Color;
    import java.util.Vector;
     
    public class Piste1 extends JFrame  {
     
        Vector touchesnoires = new Vector();
        Vector touchesblanches = new Vector();
        Vector touches = new Vector();
        Vector grille = new Vector();
        Vector data = new Vector();
        final int tl = 30, th = 10, tl1 = 60;
        JScrollPane scrollpane;
        JPanel pan;
        int xpos;
        int ypos;
        boolean mouseEntered;
        boolean rect1Clicked;
     
        public Piste1() {
            super("JScrollPane Demonstration");
            setSize(1000, 200);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            init();
            setVisible(true);
        }
     
        public void init() {
     
            Paneau p = new Paneau();
            p.setSize(2000, 300);
     
     
     
     
            int y = 0;
     
            for (int i = 0; i < 8; i++) {
     
                touchesblanches.add(new Touche(0, y, tl, th, 0));
                touchesblanches.add(new Touche(0, y += th, tl, th, 0));
                touchesblanches.add(new Touche(0, y += 2 * th, tl, th, 0));
                touchesblanches.add(new Touche(0, y += 2 * th, tl, th, 0));
                touchesblanches.add(new Touche(0, y += 2 * th, tl, th, 0));
                touchesblanches.add(new Touche(0, y += th, tl, th, 0));
                touchesblanches.add(new Touche(0, y += 2 * th, tl, th, 0));
                touchesblanches.add(new Touche(0, y += 2 * th, tl, th, 0));
            }
            touchesblanches.add(new Touche(0, y += th, tl, th, 0));
     
            for (int i = 1; i < 65; i++) {
                for (int j = 0; j < 88; j++) {
     
     
                    grille.add(new Touche(i * tl1, j * th, tl1, th, i + j * 88));
     
     
                }
            }
     
            //p = new Paneau() ;
            //getContentPane().add(p) ;
     
            JScrollPane scrol1 = new JScrollPane(p);
            scrol1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            //JScrollBar barredef = new JScrollBar();
            //affichage.add(barredef);
     
            getContentPane().add(scrol1);
     
            JScrollPane scrol2 = new JScrollPane(p);
            scrol2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
     
            getContentPane().add(scrol2);
     
     
    //        addMouseListener(this);
     
        }
     
        public class Paneau extends JPanel {
     
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g21 = (Graphics2D) g;
     
                Dimension d = getSize();
     
     
     
                g21.setBackground(getBackground());
                g21.clearRect(0, 0, d.width, d.height);
     
                g21.setColor(Color.BLACK);
                g21.fillRect(0, 0, tl, 88 * th);
     
     
     
     
     
                for (int i = 0; i < touchesblanches.size(); i++) {
                    Touche touche = (Touche) touchesblanches.get(i);
     
                    g21.setColor(Color.WHITE);
                    g21.fill(touche);
                    g21.setColor(Color.BLACK);
     
                    g21.draw(touche);
     
     
                }
                for (int i = 0; i < grille.size(); i++) {
                    Touche touche = (Touche) grille.get(i);
     
                    if (i % 2 == 0) {
                        g21.setColor(Color.WHITE);
                    } else {
                        g21.setColor(new Color(204, 204, 225));
                    }
                    g21.fill(touche);
                    g21.setColor(Color.BLACK);
     
                    g21.draw(touche);
     
     
     
                }
     
     
     
     
            }
     
            public void mouseClicked(MouseEvent me) {
     
                // Save the coordinates of the click lke this.
                xpos = me.getX();
                ypos = me.getY();
                int px, py;
     
                // Check if the click was inside the rectangle area.
                for (int i = 0; i < 88; i++) {
                    if (xpos > i * th && xpos < (i + 1) * th) {
     
                        if (xpos > i * th && xpos < (i + 1) * th) {
                            px = i * th;
                            for (int j = 0; j < 65; j++) {
                                if (ypos > j * tl1 && ypos < (j + 1) * tl1) {
                                    py = j * tl1;
                                    for (int k = 0; k < 64 * 88; k++) {
                                    }
                                }
                            }
                        }
                    }
                }
            }
     
            public void mousePressed(MouseEvent me) {
            }
     
            public void mouseReleased(MouseEvent me) {
            }
     
            public void mouseEntered(MouseEvent me) {
                // Will draw the "inside applet message"
                mouseEntered = true;
                repaint();
            }
     
     
        }
     
        public static void main(String args[]) {
            new Piste1();
     
        }
    }
    et voila la classe touche



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    import java.awt.*;
    //CLASSE TOUCHE
    public class Touche extends Rectangle{
           int Tnum ;
           boolean etatnote = false;
     
        public Touche(int x, int y, int largeur, int hauteur,int num){
        super(x, y, largeur, hauteur);
        this.Tnum=num;
        this.etatnote=false;
            }  
        }



    merci (ne pas faire attention au mouselistener)

  2. #2
    Membre éprouvé Avatar de anisj1m
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2006
    Messages
    1 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 067
    Par défaut
    Vous deviez mettre un composant dans le scroll pour le voir par exemple un panel

  3. #3
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2010
    Messages
    47
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2010
    Messages : 47
    Par défaut
    Oui, il faut remplir le viewport du JSwcrollBar avec, par exemple un JPanel, et de plus, il faut que ce composant ait une PreferedSize pour que les ascenseurs puissent être calculés comme il se doit.

Discussions similaires

  1. [Débutant] Problème avec ScrollBar
    Par h4miel dans le forum Windows Forms
    Réponses: 0
    Dernier message: 30/07/2014, 11h50
  2. [Débutant] problème avec scrollbar du dataGridView
    Par Abdelweheb dans le forum C#
    Réponses: 1
    Dernier message: 07/05/2012, 09h24
  3. Problème avec scrollBar en android
    Par khaledfayala dans le forum Android
    Réponses: 3
    Dernier message: 24/02/2012, 15h41
  4. Problème avec Scrollbar
    Par riquet90 dans le forum VB 6 et antérieur
    Réponses: 6
    Dernier message: 23/08/2010, 10h25
  5. problème avec scrollbar
    Par azerty09 dans le forum AWT/Swing
    Réponses: 6
    Dernier message: 17/02/2008, 20h01

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