문제

I have a java application which requires to add button sets contains in jpanels dynamically. ex:-

.
.

JButton button1 = new JButton("Button_1");
JButton button2 = new JButton("Button_2");

JPanel panel = new JPanel();
panel.add(button1);
panel.add(button1);
tblMainToolBar.add(panel);

.
.

above code adds the panel into the tool bar but, to see the added panel I have to minimize or maximize the main window. please assist.

도움이 되었습니까?

해결책

When adding components to a visible GUI the code should be:

panel.add(...);
panel.revalidate();

다른 팁

You need to call yourFrame.pack() after .add() .

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top