Marge / remplissage dans GridBagLayout Java

  1. Est-il possible de mettre un margin/padding dans GridBagLayout pour l'ensemble de la ligne/colonne? J'utilise l'encart sur les contraintes de l'objet-cependant, en utilisant cette approche, j'ai besoin de rembourrage de fond sur chaque composant.
  2. Est-il possible de pad tout le contenu de la JFrame? Parce que maintenant, chaque composant est aligné avec le cadre.
  constraints.weightx = 2;
  constraints.weighty = 1;
  constraints.fill = GridBagConstraints.BOTH;
  addComponent(this, layout, constraints, questionPanel = new QuestionPanel(), 0, 0, 1, 1);

  constraints.weightx = 1;
  constraints.weighty = 1;
  constraints.fill = GridBagConstraints.BOTH;
  addComponent(this, layout, constraints, categoryPanel = new CategoryPanel(), 0, 1, 1, 1);

  constraints.weightx = 1;
  constraints.weighty = 0;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  addComponent(this, layout, constraints, answerPanel = new AnswerPanel(), 1, 0, 2, 1);

  constraints.weightx = 1;
  constraints.weighty = 2;
  constraints.fill = GridBagConstraints.BOTH;
  addComponent(this, layout, constraints, tabPane = new JTabbedPane(), 2, 0, 2, 1);

  constraints.weightx = 1;
  constraints.weighty = 0;
  constraints.fill = GridBagConstraints.NONE;
  constraints.anchor = GridBagConstraints.SOUTHEAST;
  addComponent(this, layout, constraints, buttonPanel = new ButtonPanel(), 3, 1, 1, 1);

Je suis en utilisant une méthode privée addComponent:

private void addComponent(Container context, GridBagLayout _layout, GridBagConstraints            _constraints, Component component, int row, int column, int width, int height) {
  _constraints.gridx = column;
  _constraints.gridy = row;
  _constraints.gridwidth = width;
  _constraints.gridheight = height;

  _layout.setConstraints(component, _constraints);
  context.add(component);
 }

Comment puis-je ajouter un peu d'air(padding/margin)" entre les cellules?

source d'informationauteur LuckyLuke