Я пытаюсь добавить JPanel
в другой и поместить его в родительский размер JPanel.Как установить JPanel в размер JTabbedPane?
У меня есть JPanel
, который содержит JTable
и JButton
, используя этот код:
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
, просто отобразить JTable
и JButton
, но в центре панели. Я бы хотел, чтобы размер attributesPanel
был таким же, как размер открытой вкладки.
Это код, я использую, чтобы добавить JPanel в мой JTabbedPane:
TabbedPane tabbedPane = new TabbedPane();
tabbedPane.setComponentAt(1, attributesPanel);
Я попытался с помощью GridLayout
, он установлен на JPanel
хорошо, но я был не в состоянии изменить размер кнопки. Я пробовал с FlowLayout
и GridBagLayout
, но я не смог их правильно отобразить, потому что у меня была такая же проблема.
Заранее спасибо.
Измените свой вопрос включать [sscce] (http://sscce.org/) который показывает проблему, которую вы описываете, для [пример] (http://stackoverflow.com/a/11949899/230513). – trashgod