[Flextable1][Flextable2]
[Flextable3][Flextable4]
Inside every flextable: put vertical panel
inside every verticalpanel: consists of label and link shown as diagram below:
I want to use for loop in the flextable but i don't know where to start first.
Please help me to solve. Thanks.
It's a very simple code. Read inline comments for more info.
// root flex table that contains other widgets
FlexTable rootFlexTable = new FlexTable();
int counter = 0;
// 2 rows and 2 columns (change it as per your requirement)
for (int i = 0; i < 2; i++) { // rows
for (int j = 0; j < 2; j++) {// columns
counter++;
FlexTable flexTable = new FlexTable();
VerticalPanel verticalPanel = new VerticalPanel();
Label label = new Label("No " + counter + "(label)");
Hyperlink hyperlink = new Hyperlink("Name " + counter + "(link)",
"link" + counter);
verticalPanel.add(label);
verticalPanel.add(hyperlink);
// why are you using one extra flex table
// that contains only single component?
flexTable.setWidget(0, 0, verticalPanel);
// add inner flex table at row i and column j
rootFlexTable.setWidget(i, j, flexTable);
}
}
RootPanel.get().add(rootFlexTable);
Screenshot:
Related
I've tried to test TOAST functionality and created the code:
int length = 20;
using (NpgsqlConnection conn = new NpgsqlConnection(""))
{
conn.Open();
StringBuilder ct = new StringBuilder();
ct.Append("CREATE TABLE t300 (");
for (int i = 0; i < 300; i++)
{
ct.Append("i").Append(i).Append(" int not null, n").Append(i).Append(" varchar(").Append(length).Append(") not null, ");
}
ct.Remove(ct.Length - 2, 2).Append(");");
using (NpgsqlCommand cmd = new NpgsqlCommand(ct.ToString(), conn))
{
cmd.ExecuteNonQuery();
}
StringBuilder isql = new StringBuilder();
isql.Append("INSERT INTO t300 (");
StringBuilder vsql = new StringBuilder();
vsql.Append("VALUES (");
for (int i = 0; i < 300; i++)
{
isql.Append("i").Append(i).Append(", n").Append(i).Append(", ");
vsql.Append(":i").Append(i).Append(", :n").Append(i).Append(", ");
}
isql.Remove(isql.Length - 2, 2).Append(") ").Append(vsql).Remove(isql.Length - 2, 2).Append(");");
using (NpgsqlCommand cmd = new NpgsqlCommand(isql.ToString(), conn))
{
for (int i = 0; i < 300; i++)
{
cmd.Parameters.AddWithValue("i" + i.ToString(), NpgsqlDbType.Integer, i);
cmd.Parameters.AddWithValue("n" + i.ToString(), NpgsqlDbType.Varchar, length, i.ToString() + new string('n', length - i.ToString().Length));
}
for (int i = 0; i < 10000; i++)
{
cmd.ExecuteNonQuery();
}
}
}
This code fails on INSERT with exception '54000, row size (8424) exceeds limit (8160)'.
When I set 'length' variable to 26, the code works fine. Please tell me the workaround to eliminate this situation.
Postgres 12, Npgsql 4.1.5
Perhaps you have a misconception of how TOAST storage works. PostgreSQL does not compress the whole row and store it in the TOAST table, but each column of a varying length data type independently.
So after toasting, the row still consists of 600 columns, 300 of which (the integers) won't be toasted (4 bytes), and the other 300 toasted columns (the varchars) will now contain a TOAST header and a TOAST pointer.
Together this happens to be more than fits into a single block, and rows cannot span more than a single block. That causes the error.
The solution is not to use tables with so many columns. You should split the data in several tables (normalization usually takes care of that). If there are truly very many attributes to a single entity, chances are that not all of these attributes will get used in join or WHERE conditions. You could consider storing such attributes in a single jsonb column, where TOASTing will be much more efficient.
I using netbeans 8.
I need to loop to collect all employee ID from first column of jtable and store those IDs into an arraylist.
if (jTabledetail.getRowCount() > 0) {
String ecode = "";
int ishasRow = jTabledetail.getRowCount();// total 1 row
for (int r = 0; r <= ishasRow; r++) {// loop twice. First loop is gone, return to second loop or final loop for 1 row exists giving error bellow.
ecode = jTabledetail.getValueAt(r, 0).toString();
arrempcode.add(ecode);
}
}
I also tried changing to ==>> for (int r = 0; r < ishasRow; r++) but not worked.
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
at java.util.Vector.elementAt(Vector.java:474)
at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:648)
at javax.swing.JTable.getValueAt(JTable.java:2717)
I don't understand the error. I known that the error comes from loop expression. I am not sure for this error.
Now my jtable named "jTabledetail" has 1 row exists.
Do I need to change something for this case of error? I am not sure that the loop expression is wrong.
Thank you very much.
DefaultTableModel tableModel = (DefaultTableModel) TableName.getModel();
Get the row count of the table
int rowCount = tableModel.getRowCount();
Declare ArrayList
ArrayList<Object> list = new ArrayList<Object>();
Traversing table and adding values into arraylist
for(int i=0; i<rowCount; i++){
for(int j=0; j<tableModel.getColumnCount(); j++){
if(j==0){
list.add(tableModel.getValueAt(i,j));
}
}
}
I need to achieve a table that looks like the one in the picure, with space between columns. I tried:
cell.setPaddingLeft(10);
cell.setMarginLeft(10);
extractionMediaTable.setVerticalBorderSpacing(10);
But none of these seem to affect the table. Any suggestions?
This should help:
table.setBorderCollapse(BorderCollapsePropertyValue.SEPARATE);
table.setVerticalBorderSpacing(10);
table.setHorizontalBorderSpacing(10);
Some explanations:
By default iText creates tables with collapsed borders, so the first line overrides that.
Once the borders are separated, one can set the spacing (either horizontal or vertical) between them.
For example, look at the snippet below and the screenshot of the resultant pdf:
Table table = new Table(3);
table.setBorderCollapse(BorderCollapsePropertyValue.SEPARATE);
table.setVerticalBorderSpacing(10);
table.setHorizontalBorderSpacing(10);
for (int j = 0; j < 10; j++) {
for (int i = 0; i < 3; i++) {
table.addCell(new Cell().add(new Paragraph("Cell row " + j + "col " + i )));
}
}
Is there any way in iTextSharp to 'keeptogether' chapter/sections, such as PdfpTable and Paragraph?
In my case I have chapters that always contain only one tiny table. If the chaptertitle + the tiny table run out of space I would like to trigger a new page so there is no break in between them.
Thanks for an answer!
Edit:
Here is an example with chapters and paragraphs.
Each chapter has one paragraph.
If the chapter is on the bottom of the page i want it to 'trigger' a new page so that the chapter and the paragraph are always on the same site and not seperatet trough a pagebreak.
iTextManager manager = new iTextManager();
manager.NewDocument(PageSize.A4, true, 20,20,20,20);
manager.OpenForOutput(false, true,null);
for (int i = 0; i < 100; i++)
{
Chapter c = new Chapter("Chapter " + i, i);
c.TriggerNewPage = false;
c.Add(new Paragraph("Paragraph " + i));
manager.Doc.Add(c);
}
manager.SaveToFile(#"C:\temp\test.pdf", System.IO.FileMode.Create);
manager.Close();
Process.Start(#"C:\temp\test.pdf");
How to add an empty row in the grid view at the top?
Insert at index 0 in your datasource.
e.g.
DataRow newRow;
newRow = dataSet.dataTable.NewRow();
newRow[0] = "a";
newRow[1] = "b";
// ...
dataSet.dataTable.Rows.InsertAt(myNewRow, 0);