Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37360

Re: how to convert html?

From Knute Johnson <nospam@rabbitbrush.frazmtn.com>
Newsgroups comp.lang.java.programmer
Subject Re: how to convert html?
Date 2017-08-30 14:52 -0500
Organization A noiseless patient Spider
Message-ID <oo74pl$3q4$1@dont-email.me> (permalink)
References <1d4eecd0-a437-4541-841a-4cba7fef7380@googlegroups.com> <oo6n5i$i41$1@dont-email.me> <a53e0873-5233-4509-8099-b7c57b7c974e@googlegroups.com>

Show all headers | View raw


On 8/30/2017 13:41, Eric Douglas wrote:
> Best I've found so far is
> JTextPane jp = new JTextPane();
> jp.setContentType("text/html");
> jp.setText(myToolTipText);
> jp.setSize(myPrintArea);
> jp.paint(myPrintGraphics);
> 
> This seems to be working except now it is just html text, which means I can't set the font, except to do this?
> http://www.java2s.com/Tutorials/Java/Swing_How_to/JTextPane/Style_JTextPane_with_HTML_CSS_and_StyleSheet.htm

This prints a JToolTip but I still don't know a way to get the actual 
tool tip from a component or to set a JToolTip on a component.


import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;

public class PrintableToolTip extends JToolTip implements Printable {
     public PrintableToolTip(String text) {
         super();
         setTipText(text);
     }

     public int print(Graphics graphics, PageFormat pageFormat, int 
pageIndex)
      throws PrinterException {
         if (pageIndex == 0) {
             Graphics2D g = (Graphics2D)graphics;
 
g.translate(pageFormat.getImageableX(),pageFormat.getImageableY());
             paint(g);
             return Printable.PAGE_EXISTS;
         } else
             return Printable.NO_SUCH_PAGE;
     }

     public static void main(String... args) {
         EventQueue.invokeLater(() -> {
             JFrame f = new JFrame();
             f.setLayout(new GridBagLayout());

             GridBagConstraints c = new GridBagConstraints();
             c.gridx = 0;  c.insets = new Insets(2,2,2,2);

             f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
             PrintableToolTip tip = new PrintableToolTip(
              "<html>Line one<br><u>Underline one</u></html>");

             f.add(tip,c);

             JButton b = new JButton("Print");
             b.addActionListener(event -> {
                 PrinterJob job = PrinterJob.getPrinterJob();
                 job.setPrintable(tip,job.defaultPage());
                 if (job.printDialog())
                     try {
                         job.print();
                     } catch (PrinterException pe) {
                         pe.printStackTrace();
                     }
             });
             f.add(b,c);

             f.pack();
             f.setVisible(true);
         });
     }
}



-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

how to convert html? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-30 07:03 -0700
  Re: how to convert html? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-08-30 10:59 -0500
    Re: how to convert html? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-30 11:41 -0700
      Re: how to convert html? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-08-30 14:52 -0500
        Re: how to convert html? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-30 14:00 -0700
          Re: how to convert html? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-31 05:47 -0700
            Re: how to convert html? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-31 05:56 -0700
              Re: how to convert html? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-31 07:12 -0700
                Re: how to convert html? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-08-31 13:20 -0500
                Re: how to convert html? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-31 11:49 -0700
                Re: how to convert html? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-08-31 14:52 -0500
                Re: how to convert html? Eric Douglas <e.d.programmer@gmail.com> - 2017-08-31 13:37 -0700

csiph-web