DualListBox.javaの例を使用していますが、JList の幅がエントリの長さに基づいてスケーリングされるという問題があります。left JListが幅の 40% を占め、 がJButtons10% を占めright JList、 が残りの 40% を占めるのが理想的です。
private void initScreen()
{
setBorder(BorderFactory.createEtchedBorder());
setLayout(new GridBagLayout());
title = new JTextField("");
title.setEditable(false);
add(title, new GridBagConstraints(0, 0, 3, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
EMPTY_INSETS, 0, 0));
sourceLabel = new JLabel(DEFAULT_SOURCE_CHOICE_LABEL);
sourceListModel = new SortedListModel();
sourceList = new JList(sourceListModel);
sourceList.addListSelectionListener(new AddSelectionListener());
add(sourceLabel, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
EMPTY_INSETS, 0, 0));
add(new JScrollPane(sourceList), new GridBagConstraints(0, 2, 1, 5, .5, 1, GridBagConstraints.CENTER,
GridBagConstraints.BOTH, EMPTY_INSETS, 0, 0));
addButton = new JButton(ADD_BUTTON_LABEL);
add(addButton, new GridBagConstraints(1, 3, 1, 2, 0, .25, GridBagConstraints.CENTER, GridBagConstraints.NONE,
EMPTY_INSETS, 0, 0));
addButton.addActionListener(new AddListener());
removeButton = new JButton(REMOVE_BUTTON_LABEL);
add(removeButton, new GridBagConstraints(1, 5, 1, 2, 0, .25, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 5, 0, 5), 0, 0));
removeButton.addActionListener(new RemoveListener());
destLabel = new JLabel(DEFAULT_DEST_CHOICE_LABEL);
destListModel = new SortedListModel();
destList = new JList(destListModel);
destList.addListSelectionListener(new RemoveSelectionListener());
add(destLabel, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
EMPTY_INSETS, 0, 0));
add(new JScrollPane(destList), new GridBagConstraints(2, 2, 1, 5, .5, 1.0, GridBagConstraints.CENTER,
GridBagConstraints.BOTH, EMPTY_INSETS, 0, 0));
}
コンパクト グリッドDualListBBox()に追加された JPanel に追加されます
SpringUtilities.makeCompactGrid(content, 1, 1, 6, 6, 6, 6);
パネルに水平スクロールがあるかどうかはわかりません。両方を同じ幅にしたいだけです。グリッドとレイアウトに精通している人は、私にいくつかの指針を与えることができますか、それとも上記の値のコードに何か問題がありますか?
ありがとう!