Hi Razvanb Did you get a answer for how to have background color set w/o the field being in focus. I am facing a similar problem and I am actually facing it with both PdfFormField as well as TextField
1st way to create a textfield PdfFormField field = acroForm.addSingleLineTextField(name, text, m_baseFont, m_fontSize, left, bottom, right, top); 2nd way TextField tf = new TextField(writer, new Rectangle(left, bottom, right, top), name); tf.setBackgroundColor(Color.YELLOW); tf.setText(text); tf.getAppearance(); //tf.setVisibility(tf.HIDDEN); try { writer.addAnnotation(tf.getTextField()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } Both behave the same. Background color only becomes visible after the field is clicked. I have played with PdfAppearances setting them to normal, rollover and down.It does not help please share any insights. Greatly appreciated razvanb wrote: > > Hi! > I have an urgent problem! > > I made a form that has many textfields created with the method > PdfFormField.createTextField(PdfWriter writer, boolean multiline, boolean > password, int maxLen), and that because my textfields are in > PdfPCell(table cells). > My problem is that i want these textfields to have a Green background > color(in general, not only when focused), and all that i managed to do was > to set the backgroundcolor only when you focus that textfield(with > setMKBackgroundColor(Color)). > > So please...if anyone knows how this can be done...it would be of a great > help! > > Please notice that I'm not using the class Textfield, but PdfFormField, > and this is because with TextField i do not know how to insert the > textfield in a specific cell of a table. > > Any solutions are good....! > > Here is a part of the code: > > PdfPTable nested2 = new PdfPTable(2); > cell = new PdfPCell(); > form = PdfFormField.createTextField(writer, false, false, 20); > form.setFieldName("AbrufNr"); > form.setMKBackgroundColor(Color.LIGHT_GRAY); > writer.addAnnotation(form); > cell.setCellEvent(new TestMain(form, 1f, "textfieldAbrufNr")); > cell.setBorder(PdfPCell.NO_BORDER); > cell.setGrayFill(0.9f); > nested2.addCell(cell); > > ----------------------- > public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] cb) > { > if(formType.equalsIgnoreCase("textfieldAbrufNr")){ > form.setWidget(new Rectangle(rect.getLeft(padding), > rect.getBottom(padding), > rect.getLeft(padding) + 20, > rect.getBottom(padding) + 10), > PdfAnnotation.HIGHLIGHT_INVERT); > } > } > ----------------------- > The class TestMain implements PdfPCellEvent; So this method cellLayout is > executed at the end...setting the position of my textfield in the cell! > -- View this message in context: http://www.nabble.com/PdfFormfield-textfield-background-color-tp16627283p19749756.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php