0

を別のものに追加しJPanelて、親の `JPanel サイズに合わせようとしています。

私は、このコードを使用してとJPanelを含むを持っています:JTableJButton

JScrollPane attributeTable = new JScrollPane(this);

JPanel attributesPanel = new JPanel();

JPanel textFieldPanel=new JPanel();
JPanel buttonsPanel = new JPanel();

JButton newAttributeButton = new JButton("New Attribute");

attributesPanel.add(textFieldPanel, BorderLayout.CENTER);
attributesPanel.add(buttonsPanel, BorderLayout.SOUTH);

newAttributeButton.addActionListener(AttributesTableController.getInstance());

GroupLayout layout = new GroupLayout(textFieldPanel);
textFieldPanel.setLayout(layout);

// Turn on automatically adding gaps between components
layout.setAutoCreateGaps(true);

// Turn on automatically creating gaps between components that touch
// the edge of the container and the container.
layout.setAutoCreateContainerGaps(true);

// Create a sequential group for the horizontal axis.

GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();

// The sequential group in turn contains two parallel groups.
// One parallel group contains the labels, the other the text fields.
// Putting the labels in a parallel group along the horizontal axis
// positions them at the same x location.
//
// Variable indentation is used to reinforce the level of grouping.
hGroup.addGroup(layout.createParallelGroup().
         addComponent(attributeTable).addComponent(newAttributeButton));
layout.setHorizontalGroup(hGroup);

// Create a sequential group for the vertical axis.
GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(attributeTable));
vGroup.addGroup(layout.createParallelGroup(Alignment.CENTER).
         addComponent(newAttributeButton));
layout.setVerticalGroup(vGroup);

このパネル ( という名前attributesPanel) を のタブに配置するとJTabbedPane、 と が表示されますが、パネルの中央に表示されます。の寸法が開いたタブの寸法と同じであることを希望します。JTableJButtonattributesPanel

これは、JPanel を JTabbedPane に追加するために使用するコードです。

TabbedPane tabbedPane = new TabbedPane();
tabbedPane.setComponentAt(1, attributesPanel);

を使用してみましたがGridLayout、うまく収まりましたJPanelが、ボタンのサイズを変更できませんでした。FlowLayoutとで試してみましたGridBagLayoutが、同じ問題が発生したため、正しく表示できませんでした。

前もって感謝します。

4

1 に答える 1

1

あなたの例は不完全なので、何が間違っているのかわかりにくいですが、これが役立つかもしれません:

JTable table = new JTable (12, 5);
JButton button = new JButton ("Button");

JPanel panel = new JPanel ();
panel.setLayout (new BorderLayout ());
panel.add (table, BorderLayout.CENTER);
panel.add (button, BorderLayout.SOUTH);

JTabbedPane tabbedPane = new JTabbedPane ();
tabbedPane.addTab ("Tab", panel);

JFrame frame = new JFrame ();
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane ().setLayout (new BorderLayout ());
frame.getContentPane ().add (tabbedPane, BorderLayout.CENTER);
frame.pack ();
frame.setVisible (true);
于 2013-02-10T16:39:30.023 に答える