ScrollPane table not aligning acordingly - java

I have a ScrollPane named options, and 4 tables named: changeOptions, settingNames, backAndApply, overlay. I have placed the first two tables inside the overlay table, and then added the overlay table into the ScrollPane. My problem is when I try to align the table settingNames to the left of overlay, it doesn't align. Same goes for changeOptions. I activated debug, and the two tables are just pressed against each other.
This is my code:
/** Setting up a lot of variables before this, and adding them to their respected table.*/
overlay.add(settingNames).left();
overlay.add(changeOptions).right();
options = new ScrollPane(overlay, scrollStyleSkin);
overlay.setWidth(Gdx.graphics.getWidth() - options.getScrollBarWidth());
cntStage.addActor(backAndApply);
options.setFadeScrollBars(false);
options.setBounds(
0,
(white.getBounds("|").height * 2),
Gdx.graphics.getWidth(),
(Gdx.graphics.getHeight() / 2 - (white.getBounds("|").height * 2)));
overlay.debug();
If I am not doing this correctly, please tell me.

Not sure if you can align left and right in the same row. Instead you might need to call something like this: overlay.add(labelTitle).align(Align.left).padLeft(-Gdx.graphics.getWidth()).padTop(Gdx.graphics.getHeight()/25); and set correct padding for adding the second table or try calling overlay.row() and having it align on the next row with negative padding. This is all I can think of right now without seeing exactly what you mean but maybe it'll help you get some more ideas.

Related

Expandable grid Vaadin UI

I have a simple grid. Two columns with a variable amount of rows. I want to make it so i have a header row with an arrow that can collapse and show the whole grid. So when I bring up the app, only the header row is visible with an arrow, and I can click to expand/collapse to show the rest of the grid.
A TreeGrid seems like overkill since I don’t need any hierarchical structure, just the ability to collapse/expand one row. I exclusively use IE and I’ve read that Drawyer doesnt work with IE 8 and above. I return a list of the objects and the object just has two string variables.
Any help with this? I am new to Vaadin 8.
Set grid height (workaround)
As a workaround, you could set the height to be approximately the number of pixels you expect to be the height of the header.
See the Sampler demo. Click the gear icon at top to expose properties of the example Grid object. The last property shown is "Size (W x H)". Change 100% to 100px to see the effect.
Grid height set to 100%
Grid height set to 100px
You can also hide the footer (see checkbox in that property list).
I don't think this can be done with plain Vaadin. But I recommend the following simpler approach:
Initially call grid.setHeightByRows(1.5) (javadoc). This will show exactly one row and a half to indicate more data is available. A scrollbar will appear, too.
Make a new column within the grid that has a button or add a button below the grid that - when clicked - calls setHeightByRows with the number of elements in the grid and hides the button. This will show all rows.

libgdx scene2dUI layer actors position

I have a problem with configurate position of buttons on my scenes layer. I'm trying to build menu, and fill it with buttons, but they are seems to ignore commands like setPosition() etc.
Code looks like that:
Table layerMenuControls = buildMenuControlsLayer();
stage.clear();
Stack stack = new Stack();
stage.addActor(stack);
stack.setSize(GameEngine.VIEWPORT_GUI_WIDTH, GameEngine.VIEWPORT_GUI_HEIGHT);
stack.add(layerBackground);
stack.add(layerMenuControls);
private Table buildMenuControlsLayer() {
Table layer = new Table();
singleplayerButton = new Button(swsSkin, "singlePlayerButton");
singleplayerButton.setPosition((GameEngine.VIEWPORT_GUI_WIDTH / 2) - 64, 64);
layer.add(singleplayerButton);
And there is nothing happening there. Buttons are ignoring these commands and position itselfs one by one horizontally.
Is there something i could forget about?
Tables in LibGDX set the position of their children relatively. So using setPosition won't work. Instead you can make use of Align
Firstly you should set the dimensions and position of the table so it knows where to align things. I assume you want the table to take up the full screen, if not you can change width and height accordingly. The following will do that
layer.setSize(GameEngine.VIEWPORT_GUI_WIDTH, GameEngine.VIEWPORT_GUI_HEIGHT);
layer.setPosition(0,0);
Then you can position buttons etc. relative to this table.
In order to set the button in the centre of the table you can use
layer.align(Align.center);
To position in the top center you can use
layer.align(Align.center|Align.top);
To stop all of your buttons adding in one line, you need to add multiple rows to the table. In between layer.add(singlePlayerButton); and whatever other buttons you are adding, you simply call layer.row();. This positions whatever you add to the table after this on a new row directly below it. In order to make things look a bit nicer you can use padding.
Hope this helps
From the wiki on libgdx's Table:
Table is a WidgetGroup that sets the position and size of its children using a logical table...
So basically, once you added singleplayerButton to layer, its position is set by its position in the Table. setPosition will be ignored in this case. If you want to set the position of the button manually, Table is not your best option. The whole point of Table is to relieve the user from needing to define the children's position and size.

Is there always a natural "space" between cells in a table?

I created a table with "buttons" aligned onto my screen for my game I am using to learn libgdx. I want the buttons to squeeze together perfectly to form a seamless menu, however there seems to be a natural padding of 1 to 2 pixels between every cell.
Is there a way to remove that padding?
The code seems unnecessary but this is the contents of my table anyways:
table.add(buttonTyce).size(150,60).expandX().expandY().bottom().left().row();
table.add(buttonGrokk).size(150,60).bottom().left().row();
table.add(buttonCeleste).size(150,60).bottom().left().row();
table.add(buttonDaem).size(150,60).bottom().left().row();
table.add(buttonRisp).size(150,60).bottom().left().padBottom(80).row();
table.setFillParent(true);
stage.addActor(table);
Thank you for any help.
I don't think there is default space. Are you sure that the texture you are using for your buttons doesn't contain any transparent edges? Also, there's table.debug() (or something like that, check the docs) to draw lines around table cells for debugging such issues.

Column dividers in JTable or JXTable

I Have a JTable (or a JXTable to be more precise) with 3 sections of grouped columns I want to divide.
I used to have 3 tables which i programmatically linked (the scrollbar position, the sorting, the selection). I used a lot of code to get this linked, and I want to get rid of this.
Now I Am switching to 1 JXTable, because there are some things a lot nicer in this table class.
I found some (not very satisfying) solutions to almost the same problem.
Maybe some one has a good suggestion for me.
Option 1: an empty column as a divider (another color, like gray) and programatically hop over this empty column when using the arrows or tab keys.
option 2: setting the margin for just 1 side of 1 column to a larger size, so it seems like a divider. Untill now I have only found out how to set the margins for all columns
option 3: getting back to 3 seperate tables again (especially to get the tables sorted in the same way is a lot of work, because I do not want to repeat the columns in the seperate sections). This means I have to rewrite my table sorter, sorting on a non-visible column.
any suggestion is welcome (also if it's none of the three given options)
I've made something that looks somewhat like what you're going for by overriding the cell renderer on the 3rd column to have a thick right border and no other borders. You could do the same within the table column header to have the border extend up through there. It's clearly placing the border within the cell but this may be sufficient for you.
{
....
table.getColumnModel().getColumn(2).setCellRenderer(
new ThickRightBorderCellRenderer());
....
}
private static class ThickRightBorderCellRenderer
extends DefaultTableCellRenderer {
#Override
public Border getBorder() {
return BorderFactory.createMatteBorder(0, 0, 0, 3, Color.BLACK);
}
}

Get columns to stretch entire width of the table

I'm working in Java using the Vaadin framework.
I have a table with 14 columns. My problem is that that there's a small gap to the right of the last column, like the beginning of a new column that shouldn't be there..
The image shows the problem:
I've tried solving it with using column expand ratio on the last column, but this makes it abnormally big..
Do any of you know of a property you can use, CSS or Java, that makes the columns stretch over the entire width of the table without causing large column disproportion?
This is known issue, it was closed already Ticket #6677
If you set your table to fullsize that should probably close the "gap".
YourTable.setSizeFull();
I gues you ahve your table in a layout. Set this layout margin to false and also remove spacing.

Categories

Resources