Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1665 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  swing, pbm setVisible et affichage

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

swing, pbm setVisible et affichage

n°1103267
stb
Posté le 31-05-2005 à 17:55:29  profilanswer
 

Bonjour,
 
je fais une petite appli, dont voici le panneau de chargement.
Elle détail l'avancement du chargement,
et un bouton permet d'afficher/cacher, les logs (cachés par défaut).
Ceux ci sont affichés dans un JTextArea contenu dans un JScrollPane que je cache.
 
Mais lorsque j'appuie sur le bouton, rien ne se passe, tant que la fenetre n'a pas été retaillée au moins une fois apres que j'ai cliqué sur le bouton.
 
Manifestement quelquechose ne se mets pas à jour et je me perds un peu dans les paint / repaint.
 
Auriez vous une solution ?
merci d'avance.
 

Code :
  1. package panels;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5. public class Loader extends JPanel {
  6.     private JToggleButton expand = new JToggleButton("Plus d'infos" );
  7.     private JLabel infos = new JLabel();
  8.     private JLabel label1 = new JLabel("D\u00e9marrage" );
  9.     private JLabel label2 = new JLabel("Veuillez patienter pendant que l'application xxx d\u00e9marre" );
  10.     private JScrollPane scrollPane = new JScrollPane();
  11.     private JTextArea logs = new JTextArea();
  12.     private JProgressBar progress = new JProgressBar(0, 4);
  13.     public Loader() {
  14.         initComponents();
  15.     }
  16.    
  17.     private void expandActionPerformed() {
  18.         scrollPane.setVisible(expand.isSelected());
  19.         // ?
  20.     }
  21.    
  22.     private void initComponents() {
  23.         GridBagConstraints gridBagConstraints = new GridBagConstraints();;
  24.         setLayout(new java.awt.GridBagLayout());
  25.         scrollPane.setViewportView(logs);
  26.         scrollPane.setVisible(false);
  27.         logs.setEditable(false);
  28.         logs.setRows(8);
  29.         logs.setColumns(40);
  30.         label1.setFont(label1.getFont().deriveFont(Font.BOLD));
  31.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  32.         gridBagConstraints.anchor = GridBagConstraints.WEST;
  33.         add(label1, gridBagConstraints);
  34.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  35.         gridBagConstraints.anchor = GridBagConstraints.WEST;
  36.         add(label2, gridBagConstraints);
  37.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  38.         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
  39.         add(progress, gridBagConstraints);
  40.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  41.         gridBagConstraints.anchor = GridBagConstraints.WEST;
  42.         gridBagConstraints.fill = GridBagConstraints.NONE;
  43.         add(infos, gridBagConstraints);
  44.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  45.         gridBagConstraints.anchor = GridBagConstraints.EAST;
  46.         add(expand, gridBagConstraints);
  47.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  48.         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
  49.         add(scrollPane, gridBagConstraints);
  50.        
  51.         expand.addActionListener(new ActionListener() {
  52.             public void actionPerformed(ActionEvent ae) {
  53.                 expandActionPerformed();
  54.             }
  55.         });
  56.     }
  57. }

mood
Publicité
Posté le 31-05-2005 à 17:55:29  profilanswer
 

n°1103319
axk47
Java Man vs Boolet Man
Posté le 31-05-2005 à 18:50:39  profilanswer
 

stb a écrit :

Bonjour,
 
je fais une petite appli, dont voici le panneau de chargement.
Elle détail l'avancement du chargement,
et un bouton permet d'afficher/cacher, les logs (cachés par défaut).
Ceux ci sont affichés dans un JTextArea contenu dans un JScrollPane que je cache.
 
Mais lorsque j'appuie sur le bouton, rien ne se passe, tant que la fenetre n'a pas été retaillée au moins une fois apres que j'ai cliqué sur le bouton.
 
Manifestement quelquechose ne se mets pas à jour et je me perds un peu dans les paint / repaint.
 
Auriez vous une solution ?
merci d'avance.
 

Code :
  1. package panels;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5. public class Loader extends JPanel {
  6.     private JToggleButton expand = new JToggleButton("Plus d'infos" );
  7.     private JLabel infos = new JLabel();
  8.     private JLabel label1 = new JLabel("D\u00e9marrage" );
  9.     private JLabel label2 = new JLabel("Veuillez patienter pendant que l'application xxx d\u00e9marre" );
  10.     private JScrollPane scrollPane = new JScrollPane();
  11.     private JTextArea logs = new JTextArea();
  12.     private JProgressBar progress = new JProgressBar(0, 4);
  13.     public Loader() {
  14.         initComponents();
  15.     }
  16.    
  17.     private void expandActionPerformed() {
  18.         scrollPane.setVisible(expand.isSelected());
  19.         // ?
  20.     }
  21.    
  22.     private void initComponents() {
  23.         GridBagConstraints gridBagConstraints = new GridBagConstraints();;
  24.         setLayout(new java.awt.GridBagLayout());
  25.         scrollPane.setViewportView(logs);
  26.         scrollPane.setVisible(false);
  27.         logs.setEditable(false);
  28.         logs.setRows(8);
  29.         logs.setColumns(40);
  30.         label1.setFont(label1.getFont().deriveFont(Font.BOLD));
  31.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  32.         gridBagConstraints.anchor = GridBagConstraints.WEST;
  33.         add(label1, gridBagConstraints);
  34.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  35.         gridBagConstraints.anchor = GridBagConstraints.WEST;
  36.         add(label2, gridBagConstraints);
  37.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  38.         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
  39.         add(progress, gridBagConstraints);
  40.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  41.         gridBagConstraints.anchor = GridBagConstraints.WEST;
  42.         gridBagConstraints.fill = GridBagConstraints.NONE;
  43.         add(infos, gridBagConstraints);
  44.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  45.         gridBagConstraints.anchor = GridBagConstraints.EAST;
  46.         add(expand, gridBagConstraints);
  47.         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
  48.         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
  49.         add(scrollPane, gridBagConstraints);
  50.        
  51.         expand.addActionListener(new ActionListener() {
  52.             public void actionPerformed(ActionEvent ae) {
  53.                 expandActionPerformed();
  54.             }
  55.         });
  56.     }
  57. }



 
 
essaie d'appeler la méthode

Code :
  1. repaint();

aà la fin de ta méthode

Code :
  1. initComponent()

pour voir
Je n'ai pas tester pour te dire si ça marche ou pas mais ça ne devrait pas etre loin de ça...
 


---------------
"Rendez tout aussi simple que possible mais ne simplifierez rien" Albert Einstein
n°1103653
beemer
Posté le 01-06-2005 à 08:55:00  profilanswer
 

pour quoi tu fais pas directement un setVisible sur ton JTextArea ?

n°1103733
nraynaud
lol
Posté le 01-06-2005 à 09:56:28  profilanswer
 

axk47 a écrit :

essaie d'appeler la méthode

Code :
  1. repaint();

aà la fin de ta méthode

Code :
  1. initComponent()

pour voir
Je n'ai pas tester pour te dire si ça marche ou pas mais ça ne devrait pas etre loin de ça...


personellement je doute car rien n'est visible au moment où tu l'appellerais.


---------------
trainoo.com, c'est fini
n°1103822
beemer
Posté le 01-06-2005 à 10:33:24  profilanswer
 

ca marche si tu rajoutes un this.revalidate(); dans expandActionPerformed()
et ca marche aussi (et le rendu me semble mieux) si tu affiches/caches ton textarea


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  swing, pbm setVisible et affichage

 

Sujets relatifs
Affichage sous IE 5.5Probleme d'affichage d'un CString
Affichage puce dans une listeprobleme affichage japplet sous ie dans du html
Probleme affichage Japplet sous iePb d'affichage de ScrollBar et d'un JButon
Problème affichage image dans un JLabel[QT/VisualC++] pb d'affichage, conversion projet QT<->VisualC++
affichage tableau[C++] affichage d'un snake en mode texte
Plus de sujets relatifs à : swing, pbm setVisible et affichage


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR