Bonjour à toute et à tous,
Je suis en train de développer un logiciel censé afficher une partition musicale,
pour ceci je dessine ma partition dans un JPanel que je mets dans un JScrollPane
qui lui sera ajouté au contentPane de ma JFrame.
Le JPanel se dessine bien, le JScrollPane détecte bien quand activer ses scroll bars :
mais en essayant de scroll, voici le résultat (ici un scroll au maximum vers le bas) :
et après quelques scrolls supplémentaires, on ne sait plus ou on est :
Voici le code dans ma JFrame
Et le code de mon JPanel
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 public MainFrame(PartitionPanel content) { super(); this.setTitle("Music Transposer"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(true); this.content = content; Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); d.setSize(d.getWidth()*0.7, d.getHeight()*0.7); JScrollPane sc = new JScrollPane(this.content, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); this.getContentPane().add(sc); sc.setPreferredSize(d); this.pack(); this.setSize(d); this.setLocationRelativeTo(null); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.initMenus(); this.setVisible(true); }
Je ne trouve pas d'ou vient le problème, quelqu'un saurait-il résoudre ce bug ? J'ai ajouté un .rar contenant un .jar executable qui permet de mieux se rendre compte du problème
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 public PartitionPanel(Partition p) { super(); this.setLayout(null); this.pa = p; this.init(); this.globalWidth = 0; for(JPortee jp : this.portees) this.globalWidth = Math.max(this.globalWidth, jp.getWidth()); this.globalWidth += 40; this.globalHeight = 200 + 200*this.portees.size(); this.setPreferredSize(new Dimension(this.globalWidth, this.globalHeight)); this.setLocation(0, 0); } @Override protected void paintComponent(Graphics g) { //---Dessin du titre---// g.setColor(Color.black); g.setFont(new Font(Font.DIALOG, Font.BOLD, 20)); g.drawString("Partition : "+this.pa.getTitre(), 20, 30); //---------------------// //---Dessin des portées---// for(int i=0; i < this.portees.size(); i++) this.portees.get(i).paintComponent(g); //------------------------// }
Merci d'avance !
Partager