Better <h:selectManyCheckbox> layout? - java

I have a JSF page. At one point, I have a <h:selectManyCheckbox> that is displaying a number of items. The tag provides 2 attributes you can set to define whether the contents should be displayed horizontally or vertically. However, with more than a few items both choices look bad. Go with horizontal, and everything ends up bunched up. Go with vertical, and you can make your page unnecessarily long. Is there any way to get the best of both worlds? Specify that there should be x number of columns, for example? Say I have 20 items and I'd like 4 columns. If that number grew to 100, I'd still want only 4 columns. The list would then grow vertically.
Is this possible?

Use Tomahawk's t:selectManyCheckbox instead. It has a layoutWidth attribute exactly for this purpose.

There is no such tag rich:selectManyCheckbox only h:selectManyCheckbox

Related

GridBagLayout: changes alignment after adding checkbox

I have two classes which creates two different dialog box. Both the classes have same code, except one has additional lines of code, which creates a checkbox
first Class, with Checkbox
Second Class, without Checkbox
There is slight alignment difference in "save" button. How can I fix this.
Is there a particular reason you're using fixed row and column sizes? One of the great features of GridBagLayout is its ability to center/align and fill. This also tends to make things look better on different screen sizes, different fonts, etc.
To answer your specific question, my guess is that the checkbox is taller than the row you're putting it into, pushing the next row down.
When I debug GBL, I often set row/column background colors to different things and print out (or view in a debugger) sizes of the things I'm trying to fit into the container.
I had to adjust the row height as the checkbox was taller than the row and was pushing the third row downward( Thanks to Ingrid Biery). so I changed the 2nd row height from 25 to 30 and it worked.

Placing Objects in a certain layout(For game)

So this what i want to do, i have a scene right now, and i want to create "Pages" on the scene with level icons i create.
Now i want to be able to set the amount of levels i want to have. for example,
int levels = 100;
Then i want it to be able to create "Pages". What i mean by pages is it will be space between each of the level sections.
I would like to be able to set the rows and columns like this:
int rowsPerPage = 5;
int colPerPage = 10;
Each of my level icons are 80x80 width and height.
So with this information i would like be able to place the level icons on rows per page bases and column per page basis.
Each level icon should have some padding space between them.
Once it reaches its makes row and column per page on the first page i would like to create a second page making some space between the first set of rows and columns. Once it reaches is max icon per row it should then start a new row on that page
Right now im not sure where to begin. The reason i am using this is because i have set up gesture detection so my users can scroll from "Page" to "Page" to select a level.
I know this isnt a place to just ask for code, but im stuck on my current project because of this and it would be really great to get some assistance.
Thank you guys in advance.
Thank you.
No one will write your code for you if you haven't even attempted it yourself...
This is from google... It may not be exactly what you want. However, it is a start :)
http://www.andengine.org/forums/tutorials/menu-scroll-example-t5740.html

Java - Mixing component size in GroupLayout

I am trying to arrange two set of buttons for a calculator GUI. Each one uses a GroupLayout to make them. One set is the numbers (and "."), the other is for operation buttons. This basically works but if one of the buttons has double length (for example the equals button on my operations set) it throws the other buttons out of line.
I will use the operations set as an example. There are two columns and four rows of buttons. The final row only has one button - the equals. I want to make this double length stretching across both columns. At the moment it simply pushes the second column along to the end of it when I want the second column to sit on top of it.
Here's the code for the layout - operLayout is the name of the layout for the operations, left and right brackets on the first row, + and - on the second, * and / on the third and equals on the last row. Each button has a minimumSize set elsewhere (they are all the same except equals is twice as long).
operLayout.setAutoCreateGaps(true);
operLayout.setAutoCreateContainerGaps(true);
operLayout.setVerticalGroup(operLayout
.createSequentialGroup()
.addGroup(
operLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(leftBracket)
.addComponent(rightBracket))
.addGroup(operLayout.createParallelGroup().addComponent(add).addComponent(subtract))
.addGroup(operLayout.createParallelGroup().addComponent(multiply).addComponent(divide))
.addGroup(operLayout.createParallelGroup().addComponent(equals)));
operLayout.setHorizontalGroup(operLayout
.createSequentialGroup()
.addGroup(
operLayout.createParallelGroup().addComponent(leftBracket).addComponent(add)
.addComponent(multiply).addComponent(equals))
.addGroup(
operLayout.createParallelGroup().addComponent(rightBracket).addComponent(subtract)
.addComponent(divide)));
I understand why this is happening but I'm not sure how to sort it out. Is there a simple way? Or should I change the way I'm doing it? Thanks
Put the equals component in its own parallel horizontal group.
First of all, make sure you use consistent indentation when you're using GroupLayout. I have found this absolutely vital in keeping track of what's going on.
The reason you're seeing the behavior you report is because the equals sign is part of the same horizontal parallel group as the first column of buttons. So when you make it double wide, it pushes the second column of buttons to the right. This is exactly what you're telling it to do because you're telling it to stay in the first parallel group (column).
In order to get the behavior you want, you have to layout that button separately, in parallel to the other buttons. You do this by putting it in its own parallel group. You probably want to put an alignment on this group also in order to get the best behavior. I think GroupLayout.Alignment.CENTER is what you want.
Also note that you don't need to create a new group if it's only going to have one component in it. Just add that component instead.
operLayout.setVerticalGroup(operLayout.createSequentialGroup()
.addGroup(operLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(leftBracket)
.addComponent(rightBracket))
.addGroup(operLayout.createParallelGroup()
.addComponent(add)
.addComponent(subtract))
.addGroup(operLayout.createParallelGroup()
.addComponent(multiply)
.addComponent(divide))
.addComponent(equals));
operLayout.setHorizontalGroup(operLayout.createParallelGroup()
.addGroup(operLayout.createSequentialGroup()
.addGroup(operLayout.createParallelGroup()
.addComponent(leftBracket)
.addComponent(add)
.addComponent(multiply))
.addGroup(operLayout.createParallelGroup()
.addComponent(rightBracket)
.addComponent(subtract)
.addComponent(divide)))
.addComponent(equals));

How to set JtextArea to keep fixed no of rows?

How can i keep no of rows constant in text area.
I need to create a console window for my application.
If rows exceeds predefined no of rows first rows must get disposed.
As if first written row will be destroyed first when i append anything which exceeds no of rows set.
One more thing , i need to keep vertical scroll bar. That means no of rows must not be the whatever rows are visible when text area it opened.
For example : - no of visible rows on view port are 30.
It should keep 120 rows information, which will can be seen with the help of scroll bar.
Sounds like what you want to do is create your own Document implementation. See Document.
The Message Console shows one way.

How to check for empty cells in Gridbaglayout?

How to check for empty cells in gridbaglayout?
e.g. there are 100 cells, only 10 filled with label or pictures?
Well the GridBagLayout has a getConstraints(Component) method. So you could get all the components in the Container and then get the constraint for each component. The constraint will contain the gridX/gridY value which you could use to populate a 2D array. You may also not to consider the gridWidth/gridHeight values.
So the answer is yes you could derive all the information.
You can use table2gridbag to avoid producing empty cells in the first place. It's a console tool that takes an HTML table, describing the layout, and transforms it into suitable Java source code for configuring the GridbBaglayoutManager to produce an equivalent layout.

Categories

Resources