0

I started to play around with the SWT-AWT bridge and I don't manage to get a nice size for my JPanel, which sits inside a Composite. Can anybody give me a hint what is wrong with the code?

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JPanel;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.*;


public class TestSWT_AWT {
    public static void main(String[] args) {            

        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setText("SWT and Swing/AWT Example");

        Composite myComp = new Composite(shell, SWT.EMBEDDED  | SWT.NO_BACKGROUND); 

        java.awt.Frame fileTableFrame = SWT_AWT.new_Frame(myComp);
        JPanel panel = new JPanel(new BorderLayout());
        fileTableFrame.add(panel);
        panel.add(new JButton("center"),java.awt.BorderLayout.CENTER);
        panel.add(new JButton("east"),java.awt.BorderLayout.EAST);
        myComp.pack();

        shell.open();
        while (!shell.isDisposed()) {
          if (!display.readAndDispatch())
            display.sleep();
        }
        display.dispose();
    }
}

The result looks like this:

enter image description here

Instead, I would like to see something like this (swing only)

enter image description here

Antje Janosch
  • 1,154
  • 5
  • 19
  • 37

1 Answers1

1

I missed a simple line of code:

shell.setLayout(new FillLayout());
Antje Janosch
  • 1,154
  • 5
  • 19
  • 37