Bonjour dans une application j'ai une classe JPanel qui sert pour l'affichage de PDF.
Dans l'ancienne version de l'application tous les éléments de l'IHM sont fixes (composant.setBound(...)) sur tous les composants.
Je suis en train de tout refaire en gridBagLayout. Jusque la tout va bien sauf pour ma vieweuse de pdf.
j'ai du mal avec le redimensionnement du scrollpane.
La toolBox se place bien, mais la scrollpane ne s'étend pas lorsque je redimentionne ma fenetre.
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 public class ComposantAffichPdf extends JPanel{ ... private JLabel affichPdf; private JPanel panelPdf; private JScrollPane scrollPane; private JToolBar toolBar; private JButton buttonZav; ... private JButton buttonNavLeft; private ImageIcon imAaffich= null; public ComposantAffichPdf() { GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); this.setLayout(gbl); //init de la toolbar toolBar = new JToolBar(); toolBar.setPreferredSize(new Dimension(510, 40)); //init des boutons de la toolbar buttonZav = new JButton(DImage.ZOOMAV.icon(false)); buttonZav.setToolTipText("Zoom avant"); buttonZav.setBorder(new EmptyBorder(0, 5, 0, 5)); buttonZav.setBorderPainted(false); buttonZav.setEnabled(false); ... buttonNavLeft = new JButton(DImage.LEFT.icon(false)); buttonNavLeft.setBorder(new EmptyBorder(0, 5, 0, 5)); buttonNavLeft.setBorderPainted(false); buttonNavLeft.setToolTipText("Page Precedente"); buttonNavLeft.setEnabled(false); // ajout des boutons a la toolbar toolBar.add(buttonZav); toolBar.add(buttonZar); toolBar.add(buttonRot); toolBar.add(buttonRed); toolBar.add(buttonPrint); toolBar.add(buttonSav); toolBar.add(buttonNavLeft); toolBar.add(buttonNavRight); //ajout des composants au panel principal : // la toolbar gbc.gridx = gbc.gridy = 0; gbc.weightx = 1; gbc.anchor = GridBagConstraints.LINE_START; this.add(toolBar, gbc); //la jscrollpane gbc.gridy = 1; gbc.weightx = 1; gbc.fill = GridBagConstraints.BOTH; scrollPane = new JScrollPane(); this.add(scrollPane,gbc); //Jpanel contenant le pdf panelPdf = new JPanel(); affichPdf = new JLabel(); panelPdf.add(affichPdf); scrollPane.setViewportView(panelPdf); ...
J'avoue etre un peu perdu avec le scrollpane.
la partie le la JFrame qui appele le Composant d'affichage de PDF :
Mon approche est mauvaise, mais je sèche, et je ne parviens pas à faire fonctionner le redimensionnement de la scrollPane.
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 //vieweuse viewPdf = new ComposantAffichPdf(512,710); viewPdf.setMinimumSize(new Dimension(512,710)); ... panDroite.setLayout(new GridBagLayout()); // placement des compsant sur la grille (7*10) GridBagConstraints gbc2 = new GridBagConstraints(); gbc2.gridx = 0; gbc2.gridy = 0; gbc2.weightx = 1; gbc2.weighty = 1; gbc2.anchor = GridBagConstraints.FIRST_LINE_START; //gbc2.fill = GridBagConstraints.BOTH; gbc2.gridwidth = 1;// dernier composant gbc2.gridheight = 9; gbc2.insets = new Insets(5, 5, 5, 5); panDroite.add(viewPdf,gbc2);
Une idée?
Merci.
Partager