So I am working with Swing components embedded into SWT.
Here a simplified version of my issue, basically I have two Panel objects (panelA, panelB
) with some Swing components, embedded in my Shell. I want to add an on/off option on the panelB
, doing that I did except my JTree to fill out the whole Shell while panelB
is off, but it didn't...
The only way I found is recreating the components but I feel like it is not the good way to do things. (For putting off the component I am using setVisible()
)
Any ideas to make the JTree component fill the space when panelB is off?
import javax.swing.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class testCW {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Test");
shell.setLayout(new FillLayout());
Composite compositeA = new Composite(shell,SWT.EMBEDDED);
java.awt.Frame frameA = SWT_AWT.new_Frame(compositeA);
java.awt.Panel panelA = new java.awt.Panel(new java.awt.BorderLayout());
frameA.add(panelA);
JScrollPane scrollPaneA = new JScrollPane(new JTree());
panelA.add(scrollPaneA);
Composite compositeB = new Composite(shell,SWT.EMBEDDED);
java.awt.Frame frameB = SWT_AWT.new_Frame(compositeB);
java.awt.Panel panelB = new java.awt.Panel(new java.awt.BorderLayout());
frameB.add(panelB);
JButton buttonB = new JButton("Button");
panelB.add(buttonB);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
// test 1 : hide panelB or compositeB? -> run -> JTree extends well?
// test 2 : hide panelB or compositeB? -> print panelB(compositeB)
// -> run -> displays well ?
// panelB.setVisible(false);
// compositeB.dispose(); //TEST
}
display.dispose();
}
}