开发者

Problem in Java GUI

Before reading about my problem, first look at this GUI Diagram.

There are three bars at the top as follows:

  • one having buttons "pictorial view", "textual view" etc.
  • second having buttons "processes", "organisation" etc.
  • third having buttons "application to processes" etc.

After that two information bars are there.

After that a canvas window displaying the diagram.

Now, I want a GUI similar to this with the following features (relative to the above diagram):

  • At first, only first bar appears and below it a white blank canvas having no diagram appears spreading all over the GUI.

  • When the user clicks on the "pictorial view" button the second bar appears below the first bar and after that the same canvas without diagram spreading over the remaining space

  • When the user clicks on the "application" button on the second bar, the third bar appears below the second bar, and after that the same empty canvas spreading over the remaing space in the GUI.

I had tried to implement it by first having a "main panel" with BorderLayout. After that as showing in 开发者_开发问答the following figure:

mainPanel(Border Layout)
|
|--topPanel (at NORTH of the mainPanel's Border Layout)
|
|
|--centerPanel (at CENTER of the mainPanel's Border Layout)

topPanel - to contain all the bars (bars should be added dynamically when a user clicks on a button)

centerPanel - to contain the canvas and adjust its size automatically when new bars are added in the topPanel


I would use a BorderLayout for the app, with the toolbars in a northerly pane.

That north pane I'd give a vertical BoxLayout and put the 3 toolbars into 3 successive boxes. That should take care of the geometry.

I'm not sure if making a toolbar invisible will cause it not to occupy space, but that would be the simplest. Alternatively, you could dynamically add()/remove() toolbars from the north pane.


The other alternative is to go with MigLayout where you can add as many components as you need to the "top". By setting "hidemode" parameter you can specify how space will occupied by invisible components.

In general MigLayout is much more flexible for almost any task and can be used instead of any standard layout or combination of layouts

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜