Domanda

I'm trying to figure out how to manage this layout in order for it to work. I have some ideas, but rehauling the whole thing is quite a bit of work to do.

This is how it looks like (in JTextAreas: "component name (parent (parent))"):

enter image description here

I have explaind the structure at the end of the question, if you feel the need to know. This GUI is supposed to be very dynamic. You should be able to add and remove chapters, pages, questions and answers.

The GUI in the image above is made using nested JPanels (up to six layers on the thickest parts!) which most don't have thier size specified so they can adjust to the changes in the document. However, a lot of time is consumed (about a second per page) when drawing the document because the program keeps recalculating sizes of all the JPanels until they fit. So, unless I can specify the initial size (MigLayout) of a component, this method won't cut it for me.

Only alternative I have come up with is trying to put it all in one layer using MigLayout, which is doable, but I don't know how well does it work with the dynamic part of the whole thing. Removing and readding all the components (document could have over a hundred pages!) doesn't really seem as an option. Since most of the components are nested one onto another and are to move as one, this makes this solution even more difficult.

Also, all widths are fixed, while all of the heights within a page are flexible.

I really don't know how to go about this. Should I modify one of the existing ideas to work, or are there maybe libraries which are used in this type of situations? Is there another way?

Any ideas?

Also, as promised, this is the structure explained:

So, the thing important here is the JPanel inside a tab. It contains the DOCUMENT. Document itself is made up out of random number of CHAPTERS. Each CHAPTER contains random number of PAGES. PAGES have MARINGS and CONTENT. On the image, pink and red parts are the MARGNIS, while everything within is CONTENT(green). CONTENT contains a single TITLE(blue). TITLE is made out ofa single JTextArea. After the TITLE, CONTENT can contain a random number of QUESTION(orange). QUESTION contains a JLabel(number) and JTextArea in one row, and below is a it's ANSWER PANEL. ANSWER PANEL contains up to five ANSWERS(yellow). Each ANSWER has a JCheckBox, JLabel (letter) and a JTextArea all in the same row.

Here I have some things marked out:

enter image description here

È stato utile?

Soluzione

You seem to have the design you need. Break down each section and apply the required layout to achieve that section. Each section should be a self contained component.

So to my mind, start by modelling the data. You need a Document model, which contains a list of Chapters, which contains a list of Pages, which is made up of a list of Titles, which is is made up of a list of questions.

I would then provide a view for each level of the model. This will allow you to concentrate on the individual needs of each view, in isolation and reuse the code logic. It also means if you need to make changes, they will be more easy to make and reflected through the entire program

You seem to have the right idea for the Document/Chapters, being laid out within tabs.

I'd follow through. Each Page would be a self contained component, possibly using something like a GridLayout.

Each Content section would be its own component, consisting of the title editor and then the questions.

Here I'd use a BorderLyout, placing the title editor at the north position and the question panel in the center. You could then use something like a GridLayout for the questions pane.

As for the margins, you can achieve hese through the use EmptyBorders

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top