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 )));
}
}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 10 months ago.
Improve this question
Im trying to figure out to print star pattern using Dart language which implementing logic code. The existing code I use as indent so that the star have some space. Is this the right method to do so?
void main(){
for(int i = 0 ; i< 7; i++){
var stars='';
for(int j = (7-i); j > 1 ;j--) {
stars += ' ';
}
for(int j = 0; j <= i ;j++){
stars += '* ';
}
print(stars);
}
}
Here is my answer write in dartpad, change starWidth to adjust star size.
Idea is get string of the star and it padding per row then printing its.
EDIT: Updated description comment for each functional
void main() {
const starWidth = 7;
// return `*` or `space` if even/odd
starGenerator(i) => i % 2 == 0 ? "*" : " ";
// just return a string full of `space`
printPad(w) => " " * w;
// cause we need `space` between `*`, length is `w * 2 - 1`,
// return a string build of star
printStars(int w) => List.generate(w * 2 - 1, starGenerator).join('');
for (int row = 1; row <= starWidth; row++) {
// cause our width with space is `starWidth * 2`,
// padding left is `padding = (our width with space - star with with space) / 2`,
// but we only need print left side (/2) so the math is simple
// `padding = width - star with without space`
var padding = starWidth - row;
print("$row:" + printPad(padding) + printStars(row));
}
}
void main(){
for(int i = 0 ; i< 7; i++){
var stars='';
for(int j = (7-i); j > 1 ;j--) {
stars += ' ';
}
for(int j = 0; j <= i ;j++){
stars += '* ';
}
print(stars);
}
}
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));
}
}
}
Suppose:
1 A
2 B
3 C
I need to print the value corresponding to 1-> A. I have put each in an array:
d1[1,2,3] and s1[A,B,C]. Now I need to print the value in the form shown in the above:
d1[0] s1[0]
1 A
How can I do this using UnityScript? In the program, I did id printing in this format:
1 A
1 B
1 C
2 A
2 B
2 C
What you have probably done, and I'm guessing without seeing the code is something along that you have a for loop within a for loop which means you're processing the first item in the first array and then all items in the second:
for (var i = 0; i < d1.Length; i++) {
for(var j = 0; j < s1.length; j++ {
Debug.log(d1[i] + " " + s1[j])
}
}
Your options depend on the array sizes and how you want to handle them. For example if you know they're the same size consistently then
for(var i = 0; i < d1.Length; i++) {
Debug.log(d1[i] + " " + s1[i])
}
should work. I would wonder if what you're trying to achieve could be done with a different data structure such as a dictionary, etc.
[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: