Creating a space for Graphics2D drawings

百般思念 提交于 2019-12-02 13:11:47

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!