How to put an expandbar on a JPanel?

2019-09-19 09:31发布

问题:

Is there a way to add a expandbar onto a jframe or jpanel without creating each component with code (using components that is already created).

Here is the code I used: ( http://www.eclipse.org/swt/snippets/#expandbar )

Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
shell.setText("ExpandBar Example");
ExpandBar bar = new ExpandBar (shell, SWT.V_SCROLL);

I have tried to add the expandbar to the panel, as well as trying to add the display and the shell to the panel, but does not work.

Please help. Thanks

回答1:

Your code is rather incomplete, basing on the example I saw online. I don't know much about SWT but ExpandBar its not a subclass of Component nor Container so they can't be added to a Panel or Frame.
Found a good example here.

I tested it and it works.

The ExpandBar documentation is found here