Kann mir einer mal über meinen Code schauen und mir erklären warum meine TextArea bei manchen Abfragen die Größe automatisch verstellt und den Inhalt dadurch nicht anzeigt.
Ich habe in der Datenbank 10 Beschreibungen in der gleichen Tabelle.
6 von 10 Beschreibungen zeigt meine Textarea richtig an.
Bei den restlichen 4 ist die TextArea nur 2 Millimeter hoch, so dass der Inhalt nicht ersichtlich ist.
Ich habe in der Datenbank 10 Beschreibungen in der gleichen Tabelle.
6 von 10 Beschreibungen zeigt meine Textarea richtig an.
Bei den restlichen 4 ist die TextArea nur 2 Millimeter hoch, so dass der Inhalt nicht ersichtlich ist.
Java:
package Projekt;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
/**
*
* @author Tiger_Locke
*
*/
public class CreatePDF extends JDialog implements ActionListener
{
private static final long serialVersionUID = 1L;
Process process;
String textAreaContent = "";
String nameTemp = "";
JTextArea textArea = new JTextArea(40, 80);
String name = "";
JScrollPane panel = new JScrollPane(textArea);
JButton createPDF_button = new JButton();
ImageIcon pdf_icon = new ImageIcon("images/pdf_icon_15.png");
JButton exit_button = new JButton();
ImageIcon exit_icon = new ImageIcon("images/exit_new_size.jpg");
/**
*
* @param array
*/
public CreatePDF(JTextArea areaDescription, JLabel labelName)
{
super();
labelName.setFont(new Font("SansSerif", Font.PLAIN, 34));
this.setTitle("PDF erstellen");
this.setLayout(new GridBagLayout());
this.setResizable(false);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(5, 5, 5, 5);
c.weightx = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
this.add(panel, c);
panel.setOpaque(false);
textArea.setOpaque(false);
c.gridwidth = 1;
this.add(createPDF_button, c);
createPDF_button.setIcon(pdf_icon);
createPDF_button.addActionListener(this);
this.add(exit_button, c);
exit_button.addActionListener(this);
exit_button.setIcon(exit_icon);
this.pack();
this.setVisible(true);
joinText(areaDescription, labelName);
}
/**
*
* @param array
*/
public void joinText(JTextArea areaDescription, JLabel labelName)
{
this.textArea.setText("\n" + labelName.getText() +
"\n\n\n" + areaDescription.getText());
if (nameTemp == "")
{
nameTemp = labelName.getText();
}
}
/**
*
* @param text
*/
void setPDF(JTextArea textArea)
{
Document doc = new Document(PageSize.A4, 50, 50, 50, 50);
try
{
// HtmlWriter.getInstance(doc, System.out);
try
{
PdfWriter.getInstance(doc, new FileOutputStream("data/" + nameTemp + ".pdf"));
}
catch (DocumentException de)
{
de.printStackTrace();
}
doc.addTitle("Cocktail Pro");
doc.addAuthor("Dinler, Biesinger, Rupp");
doc.addSubject("Cocktail-Programm");
doc.open();
String tmp = "";
tmp += textArea.getText();
try
{
doc.add(new Paragraph(tmp));
}
catch (DocumentException de)
{
de.printStackTrace();
}
doc.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
/**
*
*/
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == createPDF_button)
{
setPDF(textArea);
this.dispose();
this.setVisible(false);
}
else if (ae.getSource() == exit_button)
{
this.dispose();
this.setVisible(false);
}
}
}
Zuletzt bearbeitet von einem Moderator: