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

  FORUM HardWare.fr
  Programmation
  Java

  GridBagLayout : La taille d'un composant prend tout le vide

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

GridBagLayout : La taille d'un composant prend tout le vide

n°1977550
lamino
Posté le 25-03-2010 à 21:45:38  profilanswer
 

Bonsoir,
 
Ca fait des heures que je cherche a resoudre le pobleme, j'espere que vous pourriez m'aider a y voir plus clair.
 
Une image vaut 1000 discours.
 
Je cherche a afficher le JComboBox "encoding" avec une taille normale, tout en remontant vers le haut le JLabel "Encoding :" (de la meme maniere que le menu "Create an empty Project" apparait )
 
 
Je vous remercie d'avance pour votre aide.
 
 
http://nsa15.casimages.com/img/2010/03/24//100324103715801581.png
 
 
 
 

Code :
  1. Toolkit tk = Toolkit.getDefaultToolkit();
  2.  Dimension d = tk.getScreenSize();
  3.  int screenHeight = d.height;
  4.  int screenWidth = d.width;
  5.  //int screenHeight = 750;
  6.  //int screenWidth = 1000;
  7.  setSize(screenWidth / 2, screenHeight / 2);
  8.  setLocation(screenWidth / 4 + 30, screenHeight / 4 + 50);
  9.  Container contentPane = getContentPane();
  10.  GridBagLayout gbl = new GridBagLayout();
  11.  contentPane.setLayout(gbl);
  12.  GridBagConstraints gbc = new GridBagConstraints();
  13.  //gbc.weightx = 0.0;
  14.  gbc.weighty = 0.0;
  15.  gbc.insets.top = 15;
  16.  gbc.fill = GridBagConstraints.BOTH;
  17.  gbc.anchor = GridBagConstraints.NORTH;
  18.  //gbc.fill = GridBagConstraints.NONE;
  19.  //gbc.anchor = GridBagConstraints.NORTHEAST;
  20.  gbc.weightx = 0.1;
  21.  add(new JLabel("Project name: " ), gbc, 0, 0, 1, 1);
  22.  gbc.weightx = 0.9;
  23.  add(projectName, gbc, 1, 0, 1, 1);
  24.  gbc.weightx = 0.1;
  25.  add(new JLabel("Project location: " ), gbc, 0, 1, 1, 1);
  26.  gbc.weightx = 0.9;
  27.  add(projectLocation, gbc, 1, 1, 1, 1);
  28.  gbc.weightx = 0.1;
  29.  add(new JLabel("Create an empty Project? " ), gbc, 0, 2, 1, 1);
  30.  gbc.weightx = 0.9;
  31.  add(emptyOpt, gbc, 1, 2, 1, 1); 
  32.  gbc.weightx = 0.1;
  33.  add(new JLabel("Project input file: " ), gbc, 0, 3, 1, 1);
  34.  gbc.weightx = 0.9;
  35.  add(inputFileBrowse, gbc, 1, 3, 1, 1);
  36.  add(inputFileName, gbc, 1, 4, 1, 1);
  37.  //gbc.weightx = 100;
  38.  //gbc.fill = GridBagConstraints.HORIZONTAL;
  39.  //gbc.anchor = GridBagConstraints.NORTH;
  40.        JComboBox encoding = new JComboBox();
  41.        encoding.setEditable(false);
  42. encoding.addItem("UTF-8" );
  43. encoding.addItem("ISO8859-1" );
  44. encoding.setSelectedIndex(0);// Default is "not empty project".
  45. encoding.setSelectedItem("UTF-8" );
  46.        gbc.weightx = 0.1;
  47. add(new JLabel("Encoding: " ), gbc, 0, 5, 1, 1);
  48. gbc.weightx = 0.9;
  49. add(encoding, gbc, 1, 5, 1, 1);
  50.  JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 25, 25));
  51.  okBT = new DHJButton(this, "OK" );
  52.  okBT.setPreferredSize(new Dimension(75, 25));
  53.  bottomPanel.add(okBT);
  54.  JButton jb = new DHJButton(this, "Cancel" );
  55.  jb.setPreferredSize(new Dimension(75, 25));
  56.  bottomPanel.add(jb);
  57.  gbc.weighty = 100;
  58.  gbc.fill = GridBagConstraints.HORIZONTAL;
  59.  gbc.anchor = GridBagConstraints.SOUTH;
  60.  add(bottomPanel, gbc, 0, 5, 2, 1);
  61.  inputFileBrowse.setEnabled(!emptyProject);


 
 
 

Code :
  1. private void add(Component c, GridBagConstraints gbc, int x, int y, int w,
  2.   int h) {
  3.  gbc.gridx = x;
  4.  gbc.gridy = y;
  5.  gbc.gridwidth = w;
  6.  gbc.gridheight = h;
  7.  getContentPane().add(c, gbc);
  8. }

mood
Publicité
Posté le 25-03-2010 à 21:45:38  profilanswer
 


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

  GridBagLayout : La taille d'un composant prend tout le vide

 

Sujets relatifs
Comment afficher une chaine avec une taille de police plus grandepb insertion champ vide dans BDD via formulaire (PHP/SQL) [Résolu]
developpement d'un composant ActiveXconnaitre la taille d'un fichier en C
recuperer la taille d'un fichier distant[résolu]comment faire pour que les cell de 2 tables ont la même taille
[VBA] Collage Variable après copie de tableau de taille variable[Acc 2000] Requete ok mais recordset vide
[DB2] extraction de database reste vide sur DB V7Entrer des données dans un tableau initialement vide
Plus de sujets relatifs à : GridBagLayout : La taille d'un composant prend tout le vide


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