List of usage examples for javax.swing JTextPane getFont
@Transient
public Font getFont()
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//w w w .jav 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) { final JTextPane textPane = new JTextPane(); final JScrollPane scrollPane = new JScrollPane(textPane); String text = "Lorem ipsum dolor sit amet, " + "consectetur adipiscing elit." + "Fusce nec sapien id diam consequat adipiscing."; textPane.setText(text);/*from ww w . ja va 2s.co m*/ JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(scrollPane); frame.setSize(new Dimension(200, 200)); frame.setVisible(true); FontMetrics metrics = textPane.getFontMetrics(textPane.getFont()); textPane.setMargin(new Insets(scrollPane.getViewport().getHeight() - metrics.getHeight(), 0, 0, 0)); }
From source file:Main.java
public static void setTabs(JTextPane textPane, int charactersPerTab) { FontMetrics fm = textPane.getFontMetrics(textPane.getFont()); int charWidth = fm.charWidth('w'); int tabWidth = charWidth * charactersPerTab; TabStop[] tabs = new TabStop[5]; for (int i = 0; i < tabs.length; i++) { int tab = i + 1; tabs[i] = new TabStop(tab * tabWidth); }/* ww w .ja v a 2s . com*/ TabSet tabSet = new TabSet(tabs); SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setTabSet(attributes, tabSet); int length = textPane.getDocument().getLength(); textPane.getStyledDocument().setParagraphAttributes(0, length, attributes, false); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(new BorderLayout()); setContentPane(panel);/*from w w w . j a v a2 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:org.cagrid.installer.steps.PresentLicenseStep.java
public void init(WizardModel m) { this.model = (CaGridInstallerModel) m; setLayout(new BorderLayout()); setSize(new Dimension(475, 161)); JPanel licensePanel = new JPanel(); licensePanel.setBackground(Color.WHITE); JTextPane textPane = new JTextPane(); licensePanel.add(textPane);//from w w w .ja va2s . c om JScrollPane scrollPane = new JScrollPane(licensePanel); scrollPane.setPreferredSize(new Dimension(475, 150)); add(scrollPane, BorderLayout.CENTER); try { StringBuilder sb = new StringBuilder(); BufferedReader r = new BufferedReader( new InputStreamReader(getClass().getResourceAsStream("/cagrid_license.txt"))); String line = null; while ((line = r.readLine()) != null) { sb.append(line).append("\n"); } textPane.setText(sb.toString()); textPane.setFont(textPane.getFont().deriveFont((float) 10)); } catch (Exception ex) { String msg = "Error loading license: " + ex.getMessage(); logger.error(msg, ex); JOptionPane.showMessageDialog(null, msg, this.model.getMessage("error"), JOptionPane.ERROR_MESSAGE); } JPanel controlPanel = new JPanel(); controlPanel.setLayout(new GridBagLayout()); add(controlPanel, BorderLayout.SOUTH); JLabel label = new JLabel(this.model.getMessage("accept.license")); controlPanel.add(label); JCheckBox checkBox = new JCheckBox(); checkBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { PresentLicenseStep.this.setComplete(evt.getStateChange() == ItemEvent.SELECTED); } }); controlPanel.add(checkBox); }
From source file:org.colombbus.tangara.EditorFrame.java
/** * This method changes the standard size of a TAB for a given JTextPane. * * @param the/*from w ww . j a v a 2 s .co m*/ * JTextPane where to apply this method. */ public void setTabSizeOf(JTextPane textPane) { int spacesPerTab = tabSize; FontMetrics fm = textPane.getFontMetrics(textPane.getFont()); int charWidth = fm.charWidth(' '); int tabWidth = charWidth * spacesPerTab; TabStop[] tabStops = new TabStop[200]; for (int j = 0; j < tabStops.length; j++) { int tab = j + 1; tabStops[j] = new TabStop(tab * tabWidth); } TabSet tabSet = new TabSet(tabStops); Style style = textPane.getLogicalStyle(); StyleConstants.setTabSet(style, tabSet); textPane.setLogicalStyle(style); }
From source file:org.geopublishing.atlasViewer.GpCoreUtil.java
public static void setTabs(final JTextPane textPane, final int charactersPerTab) { final FontMetrics fm = textPane.getFontMetrics(textPane.getFont()); final int charWidth = fm.charWidth('w'); final int tabWidth = charWidth * charactersPerTab; final TabStop[] tabs = new TabStop[10]; for (int j = 0; j < tabs.length; j++) { final int tab = j + 1; tabs[j] = new TabStop(tab * tabWidth); }/*from w w w. jav a2s .c om*/ final TabSet tabSet = new TabSet(tabs); final SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setTabSet(attributes, tabSet); final int length = textPane.getDocument().getLength(); textPane.getStyledDocument().setParagraphAttributes(0, length, attributes, false); }