Apache POI (DOCX) XWPFTable asymmetric cell - java

I want to create a table looks like
this.
but the only way to to this is with an horrible merge of cells.
i try to make two separate table but the top table, follow the cell width of bottom table like this.
There is a way to make an asymmetric table without merge cells?

You don't have to 'merge' cells, but you do have to tell it how many grid columns or rows the cell spans. Picture a grid that has a column that matches every column position, and a row that matches every row position. In your example, you would have a grid with 18 columns and 3 rows. Then for each cell that spans one or more grid column or row, you must have a span attribute that tells how many grid positions are spanned by the cell. The result is the same as merging, and it might even be what you meant by merging, but that is the way the spec reads.

Related

jtable of characters in Java

I want to create a jtable where each cell should be the size of a single character, without any separation between adjacent characters (i.e adjacent columns). There are no borders between columns so the visualization of a sequence of columns is indistinguible of a jLabel. I have tried many things like making the width of a column as small as possible until each cell is displayed as ... meaning there is no space to print the character. So say I want to have 5 consecutive cells to print the name Alice. What I have achieved so far is a table with this aspect
A l i c e
If I make the column width smaller it shows
... ... ... ... ...
And what I want is:
Alice
Thanks!!
Alvaro
What is the point of doing something like this? This will only work for a single row.
What if you have two rows:
Alice
SWITCH
The minimum width of the column will be controlled by the "W" in the second row, which means you will always have extra space around the "l" in Alice.
Why don't you just use a JPanel with a BoxLayout and then add multiple JLabels to the panel?
Anyway, if you feel you still need a JTable then you can check out the Table Column Adjuster which attempts to fit the text. The basic code would be:
TableColumnAdjuster tca = new TableColumnAdjuster(table, 0);
tca.setColumnHeaderIncluded( false );
tca.adjustColumns();
Also, make sure you use JTable.setIntercellSpacing(...) to set the Dimension to 0.

Set a specific cell width to column in XSSF Apache POI

I am trying to export a table as xlsx using Apache POI XSSF. Table has 5 columns.
First row has title block merging 5 columns. In the second row, 5 headings for the table. Remaining rows are data. I want to set width of the column as max width of each heading blocks.
I tried mySheet.autoSizeColumn(colnum) and mySheet.setColumnWidth(columnIndex, width). Problem with AutosizeColumn, it is returning the highest width of the data in all the rows. So If width of some data in table is more, table header width is becoming very large.
And for the second one, setColumnWidth, I need to know width of the header cell so I can set it to the sheet. But how to find the width of a specific cell? Had no luck yet in figuring out how to do it. Any idea on how to that?
I would suggest simple solution that I have used.
Use a condition and after writing the 2nd row, i.e. the heading row, use AutosizeColumn() it will change the cell width according to the header width and then the width will remain as it is.

Is it possible for JTable column headers to be verticaly aligned?

I'm working on a hotel booking timeline feature for hotel management system. I have a JTable where rows represent rooms and columns represent days. If room is booked for that day, the corresponding cell is highlighted. Since these cells don't have any content and only serve to visually represent days when the rooms are booked, it seems rather pointless for them to have width larger then height. But if I adjust them to be equal column headers containing days are shortened and instead of "02.01.2012." all I see is "...". Since this is not an option I was wondering is it possible to "rotate" the header cells so the text in them is aligned vertically.
You may use the method described in Vertical Table Header Cell Renderer to show the header text in a vertical manner.

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