Example usage for javax.swing JTextPane setBounds

List of usage examples for javax.swing JTextPane setBounds

Introduction

In this page you can find the example usage for javax.swing JTextPane setBounds.

Prototype

public void setBounds(int x, int y, int width, int height) 

Source Link

Document

Moves and resizes this component.

Usage

From source file:MainClass.java

public void paintToPDF(JTextPane ta) {
    try {//from   www. j av a  2s.  co m
        ta.setBounds(0, 0, (int) convertToPixels(612 - 58), (int) convertToPixels(792 - 60));

        Document document = new Document();
        FileOutputStream fos = new FileOutputStream("2.pdf");
        PdfWriter writer = PdfWriter.getInstance(document, fos);

        document.setPageSize(new com.lowagie.text.Rectangle(612, 792));
        document.open();
        PdfContentByte cb = writer.getDirectContent();

        cb.saveState();
        cb.concatCTM(1, 0, 0, 1, 0, 0);

        DefaultFontMapper mapper = new DefaultFontMapper();
        mapper.insertDirectory("c:/windows/fonts");

        Graphics2D g2 = cb.createGraphics(612, 792, mapper, true, .95f);

        AffineTransform at = new AffineTransform();
        at.translate(convertToPixels(20), convertToPixels(20));
        at.scale(pixelToPoint, pixelToPoint);

        g2.transform(at);

        g2.setColor(Color.WHITE);
        g2.fill(ta.getBounds());

        Rectangle alloc = getVisibleEditorRect(ta);
        ta.getUI().getRootView(ta).paint(g2, alloc);

        g2.setColor(Color.BLACK);
        g2.draw(ta.getBounds());

        g2.dispose();
        cb.restoreState();
        document.close();
        fos.flush();
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:es.ubu.XRayDetector.interfaz.PanelAplicacion.java

/**
 * Gets the application log./*from w  w w. ja va 2  s .c o m*/
 * 
 * @param panelLog The panel of the log.
 * @return The application log.
 */
private JTextPane getTxtLog(JPanel panelLog) {
    JTextPane textPaneLog = new JTextPane();
    textPaneLog.setBounds(4, 4, 209, 195);
    textPaneLog.setEditable(false);
    panelLog.add(textPaneLog);
    textPaneLog.setContentType("text/html");
    kit = new HTMLEditorKit();
    doc = new HTMLDocument();
    panelLog_1.setLayout(null);
    textPaneLog.setEditorKit(kit);
    textPaneLog.setDocument(doc);

    textPaneLog.setText("<!DOCTYPE html>" + "<html>" + "<head>" + "<style>" + "p.normal {font-weight:normal;}"
            + "p.error {font-weight:bold; color:red}" + "p.exito {font-weight:bold; color:green}"
            + "p.stop {font-weight:bold; color:blue}" + "</style>" + "</head>" + "<body>");
    JScrollPane scroll = new JScrollPane(textPaneLog);
    scroll.setBounds(10, 16, 242, 254);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    panelLog.add(scroll);
    return textPaneLog;
}