开发者

Laying out JPanels to make a simple GUI

first of all, this is more or less my first GUI and ive learned Java for not more then a week, so it might contain some serious programming errors.

What i have right now is: Buttons and labels are part of OptionPanel and are on the left, DrawingPanel is about 5x5 px in size and is on the right.

What I am trying to do is a 开发者_高级运维simple test, to get me more familiar with the GUI. The rectangle should be movable and re-sizeable by the user when clicking the respective buttons: http://www.upload.ee/image/612005/JFrame2.jpg

Right now i have:

JFrame MainFrame - Makes JFrame (Not using the setSize function. using .pack() instead. not sure about it)

JPanel MergedPanel - FlowLayout - Adds JPanel OptionsPanel and JPanel DrawingPanel together and gets injected to JFrame MainFrame

JPanel DrawPanel - This JPanel is responsible of drawing the rectangle. JPanel OptionPanel - FlowLayout - This JPanel is responsible of the buttons.

Help please.


You should never call setSize() in your code. In Java, you use layout managers to do the layout (read that tutorial).

Subclassing JPanel to implement different parts of which the UI is composed is a good practice, but should not be overdone (it's fine to have an UI class that adds 3 other plain JPanel instances to itself for layout purposes).


Check out MiG Layout : one can make pretty easily java layouts with that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜