How to merge rows in a JTable dynamically? [duplicate] - java

Hi I'm having a problem with Java JTable. I want to merge or span cells. I did it using this examples:
http://www.java3z.com/cwbwebhome/article/article5/swing_example/JTableExamples4.html
(last 2 ones)
It works but the header and the cells width are not the same size. The problem agravates when there are more 20 columns, the last cells appear just half. Does anyone know how to solve this problem of synchronizing cells and headers? Does anyone have another CellSpan example/way?
If someone try to run this examples will get StackOverFlow error,to solve, justo change this line: setColumnIdentifiers(columnNames); to columnIdentifiers = columnNames; at AttributiveCellTableModel class. Thanks in Advance!!

The same example is available here. It seems the problem might be in MultiSpanCellTable getCellRect() implementation. Column margin is contributing to the cell width and generating this offset. Looks like the problem goes away if you replace:
cellFrame.width = aColumn.getWidth() + columnMargin;
with:
cellFrame.width = aColumn.getWidth();

Related

Adding a summary header for columns and rows

I would like to add a single header for a group of columns and rows.
I've tried using ColumnGroupHeaderLayer but the text is in the centre of the column. Instead I would like it to always have the text drawn in the centre of the visible cell and always remain in the same position as I scroll.
I've looked through a lot of documentation but I'm struggling to find anything on how I could do this.
Example
Is it possible to achieve this with NatTable?
I answered the question in the forum where you posted at the same time
https://www.eclipse.org/forums/index.php/t/1099224/

How can I resolve the printing issue for the document that is modified by apache poi

I want to ask a question which is related to apache poi and generated file printing. What I am doing is I am opening a .docx file, inserting some data and saving and printing it.
I am having a file with only 1 table which is something like:
document table
Now, if there are 'n' items, I am generating n-1 rows which copies the format of row 3.
First item is inserted in row 3, if there's another item I am adding a row in the table and saving it likewise I am creating the rows.
Now I want to make this table length = page length. For this I am counting exactly how many rows this page can incorporate and based on that I am inserting empty lines without inside top and bottom border.
The file does not have any header/ footer or any other details as of now.
While I am creating the file I am shown the file which is coming in print preview of covering the whole page of size A4.
But this document is printed only on 80% of paper. I am having 0.3 cm margins but in print the whole page is not printed.
This does not seem to be the printer issue because if other software like Google Chrome are used then it prints the complete page.
So I want to ask that how can I solve this? I tried to search about this but till now I couldn't solve it. I think of this as an issue that whenever I am using XWPFDocument, its margins and all are changed set to default size. I don't know whether this is the issue or something other is, do I need to write some commands to preserve the margins and all or there's something that I need to do.
How can I solve this thing?
Thank you.

How to create two column and with auto number in jasper report to excel?

Hello i have a problem to create report that need to display as two column, but my output is like this
the focus is the auto numbering value, anyone could help me??
It's hard to say without reviewing some code but it looks like your code is entering your entires by alternating columns. You should fill the first column with entries before moving onto the second column (to achieve your desired numbering).

JList: Horizontal_WRAP fitted?

Hey,.. i wanna show pictures with names onit in a jList, i know it get's also in a JPanel but i'm now using a jList, doesn't matter..
My question is why does the jlist don't fit the images only in 2 horizontal 'cells' and then go one row down?
sry my english is bad and i don't know how to describe it better, but look on the picture, why does the jlist dont set the e.g. 3rd picture right next to the 2nd?
JList.HORIZONTAL_WRAP works correctly in the ListDialog JWS demo, as described in Initializing a List. I suspect a layout problem, but you might compare your code to the examples found there.
If you use HORIZONTAL_WRAP you can adjust the number of columns with setVisibleRowCount. If you want them automatically fitted to the width of the list, use 0 or something negative.

Changing the size of columns in a JTable

I am creating a GUI program and I need a table with different sized columns. How do I change it so that the 1st column is smaller than the 2nd and 3rd column?
You need to get a handle to the TableColumnModel, and from there you are able to set the individual column widths. For example:
JTable tbl = new JTable();
TableColumnModel colMdl = tbl.getColumnModel();
colMdl.getColumn(0).setPreferredWidth(100);
colMdl.getColumn(1).setPreferredWidth(150);
colMdl.getColumn(2).setPreferredWidth(150);
Also, here's some useful example code showing how to "pack" a given column to be wide enough to show all values in the JTable. I typically use a modified version of this in my GUIs and will "pack" the table when the first row is added to it - After this I allow the user to control the widths.
Have you read the Swing tutorial yet? All you questions are basic and are covered in the tutorial.
You will find the tutorial has a working example that does exactly this. We should not have to spend time reminding you to read the tutorial FIRST before posting a question.
"Teach somebody to fish and they eat for life. Give somebody a fish and they eat for a day."
(and then they come back and ask another question, which is why spoonfeeding answers is not a good idea.)

Categories