Creating a space for Graphics2D drawings

后端 未结 1 1098
余生分开走
余生分开走 2021-01-29 07:07

I want to draw a simple board made of Graphics2D rectangles but I also want to have one JButton under this board. I know the exact dimensions of this board in pixels and I was t

相关标签:
1条回答
  • 2021-01-29 07:25

    I want to draw a simple board made of Graphics2D rectangles

    When you do custom painting you also need to override the getPreferredSize(...) method of your component to return the size of the comoponent.

    Then the layout manager can use this information and you will not need to use the rigid area.

    When you add the components to the frame you can just use the default BorderLayout:

    frame.add(board, BorderLayout.CENTER);
    frame.add(button, BorderLayout.SOUTH);
    

    I suggest you read the Swing tutorial. There are section on custom painting and using layout managers that will provide more detail and examples.

    0 讨论(0)
提交回复
热议问题