0

I'm trying to put two canvas elements, so that each half of the screen occupied by. But when I use the FlowLayout both canvas placed in the center, on each other.

I have the following result: enter image description here

I want to get as in the following picture: enter image description here

My code:

public class SigForApplication extends Frame{

public SigForApplication(String title) {
    commonInit(title);
    sigInit();
}

public static void main(String[] args) {
    SigForApplication a = new SigForApplication("SigFor");

}

private void commonInit(String title) {
    this.setTitle(title);
    this.setLayout(new FlowLayout());
    this.setSize(800, 400);
    this.setVisible(true);
    this.addWindowListener(
            new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dispose();
            System.exit(0);
        }
    });
}

private void sigInit() {

    SignatureCanvasInput sigCanvasIn = new SignatureCanvasInput();
    sigCanvasIn.setSize(new Dimension(400, 200));
    this.add(sigCanvasIn);

    SignatureCanvasInput sigCanvasOutput = new SignatureCanvasInput();
    sigCanvasOutput.setMaximumSize(new Dimension(400, 200));
    this.add(sigCanvasOutput);

}
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
nanotexnik
  • 328
  • 3
  • 10
  • 1
    Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson Sep 21 '13 at 15:06
  • Thanks you! I'll think about switching to swing – nanotexnik Sep 21 '13 at 16:56

1 Answers1

2

Use a GridLayoutfor this, with just two components in a single row. The components in a grid layout are assigned equal size.

See also the Laying Out Components Within a Container lesson of the tutorial, and as camickr suggested, particularly the Visual Guide to Layout Managers.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 2
    +1 (for beating my by a few seconds), See the Swing tutorial on [Layout Managers](http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html) for more information and examples. (I find linking to the tutorial more helpful than linking to the API, since the OP should know how to use the API). – camickr Sep 21 '13 at 15:09
  • @camickr Good point, it's just I always have the JDocs open and it is a few milliseconds quicker to grab the link to the class name. Bad habits.. ;) – Andrew Thompson Sep 21 '13 at 15:20