JTable Rowborder? - java

I wanna make a lineborder for a WHOLE ROW !
Not only for one cell,.. i have different cellrenderers but i wanna make a border around these cells in one row..
any idea? is there a DefaultRowRenderer, or something else?
Thanks a lot.

Table Row Renderering shows one approach for this without creating custom renderers.

If your cell renderer was smart enough not to draw the right hand side when in column 0, and not draw the left hand side when in column n - 1, then it would effectively look like a row border.

Related

How to style multi list codename one?

I am having a bit of a snag with multi list. I need to fill the multi list with some color. I managed to fill it but still there are some kind of a border that I can't cover. I tried margin 0, padding 0 but the border still exists. I even put a border on the lines and the list, still the same result. I tried putting background for everything. The only choice left is to switch the white borders to black
This looks like it's coming from the MultiButton UIID which you probably won't want to customize. You can workaround this by using:
list.getSelectedButton().setUIID("Container");
list.getUnselectedButton().setUIID("Container");
I suggest avoiding lists entirely as discussed in this post.

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.

ScrollPane table not aligning acordingly

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.

Using MouseListener to select a range of cells in a grid

Linked post: How to use MouseListener to find a specific cell in a grid
I am trying to create a Battleships game, with a 10x10 grid made up of 100 cells. The Grid extends JPanel and the Cell also extends JPanel. Earlier on I made the link above to ask how to implement a MouseListener to do this. As the code is all on that page, I am just going to refer to it.
Someone posted an excellent answer on that link which I accepted. I can now use MouseListener to detect movement, clicks etc in any cell on the grid.
However, I've hit another road block. I am trying to place ships on my grid. I am forgetting about orientation for now (as I'm assuming all ships will be placed horizontally). The first ship will take up five cells. I would like to move my cursor onto a cell on the grid and have four other 'tail' cells, to the right of the cell the cursor is over, highlighted as well. If there aren't five free cells in total (perhaps because the cursor is too near the edge of the grid), the cells will turn red. Otherwise, they will turn green.
After the first ship is placed, the second will need placing. It is four cells long. Therefore, when hovering over a cell it will have a 'tail' of three cells and so on.
I am happy with how to change colours, how to handle orientation and how to change from five ships to four ships and so on. However, I have no idea how to select multiple cells at once.
Does anybody know how to implement this? I would love to post what I have tried but the truth is, I've got nothing.
use JButtons / JToggleButtons instead of JPanels
you can to use Icon (one Image splitted to desired numbers)
by usage of implemented methods in API
use ActionListener for (undecorated) JButton
override ButtonModel for implemented mouse events (without / not required to add MouseListner) in JButton
Generally, selecting a row or column of cells is the same as selecting a rectangle of cells.
The mouseClicked method sets the initial cell.
The mouseMoved method sets the current cell that the mouse is in. This is so you can visually indicate to the user what cells have been "selected".
The mouseReleased method sets the final cell.
You check to see that the initial cell to the final cell makes up a row or a column. The length of the row or column determines which ship you place. This allows you to place the ships in any order, not just largest to smallest.
You'll have to add a MouseMoveListener to use the mouseMoved method.

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);
}
}

Categories

Resources