List of usage examples for javax.swing JTextPane setContentType
@BeanProperty(bound = false, description = "the type of content") public final void setContentType(String type)
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane ta = new JTextPane(); ta.setContentType("text/html"); ta.setText("<HTML><BODY><CODE> import java.io.*; <br> public class MyIO{}</CODE><br></BODY></HTML>"); JScrollPane jsp = new JScrollPane(ta); f.getContentPane().add(jsp);/*w ww .j a v a2 s . c om*/ f.setSize(300, 200); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String HTMLTEXT = "<html><head><style>.foot{color:red} .head{color:black}</style></head>" + "<span style='font-family:consolas'>java2s.com</span><br/>" + "<span style='font-family:tahoma'>java2s.com</span>"; JTextPane textPane1 = new JTextPane(); textPane1.setContentType("text/html"); textPane1.setText(HTMLTEXT);//from w w w .j a v a 2s . c o m JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(textPane1)); f.setSize(320, 240); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 100; i++) { sb.append("this is a test. "); }/*from w ww . j a va2s. c om*/ JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane newsTextPane = new JTextPane(); newsTextPane.setContentType("text/html"); newsTextPane.setEditable(false); newsTextPane.setText(sb.toString()); JScrollPane scrollPane = new JScrollPane(newsTextPane); scrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); frame.add(scrollPane); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String HTMLTEXT = "<html><head><style>.foot{color:red} .head{color:black}</style></head>" + "<span style='font-family:consolas'>java2s.com</span><br/>" + "<span style='font-family:tahoma'>java2s.com</span>"; JTextPane textPane1 = new JTextPane(); textPane1.setContentType("text/html"); textPane1.setFont(new Font("courier new", Font.PLAIN, 32)); textPane1.setDocument(new HTMLDocument() { @Override//from w ww . j a v a 2 s .c o m public Font getFont(AttributeSet attr) { StyleContext styles = (StyleContext) getAttributeContext(); Font f = styles.getFont(attr); String ff = f.getFamily(); System.out.println(ff); return textPane1.getFont(); } }); textPane1.setText(HTMLTEXT); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(textPane1)); f.setSize(320, 240); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame jframe = new JFrame(); jframe.setSize(500, 200);/*from w w w .j a v a 2 s .c om*/ jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane jTextPane = new JTextPane(); jTextPane.setEditorKit(new HTMLEditorKit()); JButton btn = new JButton("Print"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { jTextPane.setContentType("text/html"); boolean done = jTextPane.print(); if (done) { System.out.println("Printing is done"); } else { System.out.println("Error while printing"); } } catch (Exception pex) { pex.printStackTrace(); } } }); jframe.add(btn, BorderLayout.SOUTH); jframe.add(jTextPane); jframe.setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(new BorderLayout()); setContentPane(panel);//from ww w . j a v a 2 s .c o m JTextPane textA = new JTextPane(); textA.setName("text"); textA.setContentType("text/html"); DefaultCaret caret = (DefaultCaret) textA.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); JScrollPane filler = new JScrollPane(textA, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JTextPane textB = new JTextPane(); textB.setName("text" + "_T"); textB.setFont(textA.getFont()); DefaultCaret caret_T = (DefaultCaret) textB.getCaret(); caret_T.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); JScrollPane filler_T = new JScrollPane(textB, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); panel.add(filler, BorderLayout.NORTH); panel.add(filler_T, BorderLayout.CENTER); pack(); }
From source file:net.itransformers.topologyviewer.rightclick.impl.CLIReportViewer.java
public <G> void handleRightClick(JFrame parent, String v, Map<String, String> graphMLParams, Map<String, String> rightClickParams, File projectPath, File versionDir) throws Exception { Logger logger = Logger.getLogger(CLIReportViewer.class); JFrame frame = new JFrame(" report for " + v + " "); frame.setSize(600, 400);/*from w ww. j a v a2 s . c o m*/ frame.getContentPane().setLayout(new BorderLayout()); JTextPane text = new JTextPane(); text.setEditable(true); text.setContentType("text/html"); String postDiscoveryFolderPath = rightClickParams.get("post-discovery-file-path"); String reportFileName = rightClickParams.get("reportFileName"); logger.info("CLI report executed in " + versionDir + " for " + File.separator + postDiscoveryFolderPath + File.separator + v + File.separator + reportFileName); File xmlReport = new File(versionDir.getAbsolutePath() + File.separator + postDiscoveryFolderPath + File.separator + v + File.separator + reportFileName); if (xmlReport.exists()) { text.setText(FileUtils.readFileToString(xmlReport)); JScrollPane scrollPane = new JScrollPane(text); frame.getContentPane().add("Center", scrollPane); frame.setVisible(true); } else { JOptionPane.showMessageDialog(parent, "Report does not exist! Please generate it first!"); } }
From source file:net.itransformers.topologyviewer.rightclick.impl.NodeStatisticsRightClickHandler.java
public <G> void handleRightClick(JFrame parent, String v, Map<String, String> graphMLParams, Map<String, String> rightClickParams, File projectPath, File versionDir) throws Exception { Logger logger = Logger.getLogger(NodeStatisticsRightClickHandler.class); JFrame frame = new JFrame(" report for " + v + " "); frame.setSize(300, 200);/*from w w w .j a v a2s.c o m*/ frame.getContentPane().setLayout(new BorderLayout()); JTextPane text = new JTextPane(); text.setEditable(true); text.setContentType("text/html"); StringBuilder sb = new StringBuilder(); TopologyManagerFrame viewer = (TopologyManagerFrame) parent; final GraphViewerPanel viewerPanel = (GraphViewerPanel) viewer.getTabbedPane().getSelectedComponent(); final MyVisualizationViewer vv = (MyVisualizationViewer) viewerPanel.getVisualizationViewer(); Graph currentGraph = viewerPanel.getCurrentGraph(); int inDegree = currentGraph.inDegree(v); int outDegree = currentGraph.outDegree(v); sb.append("Number of incoming edges: ").append(inDegree); sb.append("\n"); sb.append("Number of outgoing edges: ").append(outDegree); text.setText(sb.toString()); JScrollPane scrollPane = new JScrollPane(text); frame.getContentPane().add("Center", scrollPane); frame.setVisible(true); }
From source file:com.ethercamp.harmony.desktop.HarmonyDesktop.java
private void showErrorWindow(String title, String body) { try {//from w ww . j av a 2 s . co m UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // System.setProperty("apple.awt.UIElement", "false"); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); JTextArea textArea = new JTextArea(body); JScrollPane scrollPane = new JScrollPane(textArea); textArea.setLineWrap(true); textArea.setFont(Font.getFont(Font.MONOSPACED)); textArea.setEditable(false); textArea.setWrapStyleWord(true); scrollPane.setPreferredSize(new Dimension(500, 500)); JTextPane titleLabel = new JTextPane(); titleLabel.setContentType("text/html"); // let the text pane know this is what you want titleLabel.setText("<html>" + "<b>" + title + "</b>" + "</html>"); // showing off titleLabel.setEditable(false); titleLabel.setBackground(null); titleLabel.setBorder(null); panel.add(titleLabel); panel.add(scrollPane); final JFrame frame = new JFrame(); frame.setAlwaysOnTop(true); moveCenter(frame); frame.setVisible(true); JOptionPane.showMessageDialog(frame, panel, "Oops. Ethereum Harmony stopped with error.", JOptionPane.CLOSED_OPTION); System.exit(1); } catch (Exception e) { log.error("Problem showing error window", e); } }
From source file:com.mindcognition.mindraider.ui.swing.concept.annotation.renderer.AbstractTextAnnotationRenderer.java
private void configureViewer(JTextPane viewerPane) { viewerPane.setContentType("text/html"); kit = new HTMLEditorKit(); viewerPane.setEditorKitForContentType("text/html", kit); viewerPane.setEditable(false);// w w w.j ava 2 s. c o m disableViewer(); setViewerText(""); viewerPane.addHyperlinkListener(new TextAnnotationPreviewHyperlinkListener(getConceptPanel(), viewerPane)); }