int size = sampleTextPane.getFont().getSize(); if (size < 14) size = 14; sampleTextPane.setFont(unicodeFont.getFont().deriveFont((float)size));
private void recalculateDDLFrameSize(JInternalFrame ddlFrame, JTextPane txtDDL, String[] lines) { FontMetrics fm = txtDDL.getFontMetrics(txtDDL.getFont()); int txtHeight = fm.getHeight() * lines.length; int txtWidht = 0; for (int i = 0; i < lines.length; i++) { txtWidht = Math.max(txtWidht, fm.stringWidth(lines[i])); } BasicInternalFrameUI ui = (BasicInternalFrameUI) ddlFrame.getUI(); int titleHeight = ui.getNorthPane().getHeight(); ddlFrame.setSize(txtWidht + 20, txtHeight + titleHeight + 20); }
int size = sampleTextPane.getFont().getSize(); if (size < 14) size = 14; sampleTextPane.setFont(unicodeFont.getFont().deriveFont((float)size));
/** * Returns the width, in pixels */ private int lineNumberWidth(JTextPane textPane) { int lineCount = getEtalon(); setLineNumberWidth(textPane.getFontMetrics(textPane.getFont()) .stringWidth(lineCount + " ")); return getLineNumberWidth(); }
/** Creates new form SpeakerWindow */ public SpeakerWindow() { initComponents(); // Auto-generated in NetBeans defaultPromptFont = jTextPane_PromptDisplay.getFont(); // Set icon image in upper left corner to the 16 x 16 pixel image this.setIconImage(Toolkit.getDefaultToolkit().getImage(IconSet.LOGO_16x16_URL)); }
/** * Return an int containing the wrapped line index at the given position * @param component JTextPane * @param int pos * @return int */ public int getLineNumber(JTextPane component, int pos) { int posLine; int y = 0; try { Rectangle caretCoords = component.modelToView(pos); y = (int) caretCoords.getY(); } catch (BadLocationException ex) { } int lineHeight = component.getFontMetrics(component.getFont()).getHeight(); posLine = (y / lineHeight) + 1; return posLine; }
/** * Further initialization of components on startup (These can be edited in NetBeans, initComponents() cannot) */ private void initMoreComponents() { // Center window in the user's screen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = getSize(); setLocation(new Point((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2)); // Set application icon in title bar left-hand corner this.setIconImage(Toolkit.getDefaultToolkit().getImage(IconSet.LOGO_16x16_URL)); // Change status icon in Admin window jLabel_SessionStatus.setIcon(IconSet.STOP_48X48); defaultPromptFont = jTextPane_PromptDisplay.getFont(); speakerWin.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { jCheckBoxMenuItem_SpeakerWindow.setSelected(false); } }); optionsDialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { speakerWin.showOrHidePromptCount(); } }); }
jtp.setFont(new Font(Font.DIALOG, Font.PLAIN, 14)); if (!header.isEmpty()) { aText = String.format(header, jtp.getFont().getFamily()) + aText;
public void resetFont() { final Font currFont = textPane.getFont(); textPane.setFont(new Font(Font.MONOSPACED, currFont.getStyle(), currFont.getSize())); }
JTextPane pane = new JTextPane(); Font font = pane.getFont(); pane.setContentType("text/html"); pane.setText("<html><font face=\"" + font.getFamily() + "\" size=\"" + font.getSize() + "\"></font>This is some text!</html>");
public void resetFont() { final Font currFont = textPane.getFont(); textPane.setFont(new Font(Font.MONOSPACED, currFont.getStyle(), currFont.getSize())); }
private JPanel getPanelMsg() { if (panelMsg == null) { panelMsg = new JPanel(new BorderLayout()); JPanel aux = new JPanel(); aux.add(new JLabel(getImageIcon())); panelMsg.add(aux, BorderLayout.WEST); JTextPane textPane = new JTextPane(); textPane.setText(msg); textPane.setFont(textPane.getFont().deriveFont(Font.BOLD)); textPane.setBackground(null); textPane.setEditable(false); panelMsg.add(textPane, BorderLayout.CENTER); } return panelMsg; }
@Override public Component getDetailComponent() { IssueDetailSplitPanel panel = new IssueDetailSplitPanel(); panel.firstTextPane.setText(sourceEntry.getSrcText()); panel.lastTextPane.setText(targetEntry.translation); panel.setMinimumSize(new Dimension(0, panel.firstTextPane.getFont().getSize() * 6)); return panel; } }
private void savePreferences() { properties.setProperty("font_size", Integer.toString(editorPane.getFont().getSize())); try { propertiesFile.getParent().mkdirs(); properties.storeToXML(propertiesFile.outputStream(), ""); } catch (IOException e1) { e1.printStackTrace(); } }
@Override public void keyReleased(KeyEvent e) { if (e.isControlDown() && e.getKeyChar() == '+') { Font font = editorPane.getFont(); if (font.getSize() < 24) { Font f2 = new Font(font.getName(), font.getStyle(), font.getSize() + 2); editorPane.setFont(f2); StyleConstants.setFontSize(editorPane.getStyle(StyleContext.DEFAULT_STYLE), f2.getSize()); } } else if (e.isControlDown() && e.getKeyChar() == '-') { Font font = editorPane.getFont(); if (font.getSize() > 12) { Font f2 = new Font(font.getName(), font.getStyle(), font.getSize() - 2); editorPane.setFont(f2); } } savePreferences(); lines.setFont(new Font(Font.MONOSPACED, Font.PLAIN, editorPane.getFont().getSize())); super.keyPressed(e); } });
public void handleAppEvent(AppEvent event) { commandTextArea.setFont(commandTextArea.getFont().deriveFont((float) AppPreferences.getFontSize())); doLayout(); } });
@Override public Component getDetailComponent() { IssueDetailSplitPanel panel = new IssueDetailSplitPanel(); panel.firstTextPane.setText(ste.getSrcText()); panel.lastTextPane.setText(targetText); StyledDocument doc = panel.lastTextPane.getStyledDocument(); doc.setCharacterAttributes(result.start, result.end - result.start, ERROR_STYLE, false); panel.setMinimumSize(new Dimension(0, panel.firstTextPane.getFont().getSize() * 6)); return panel; }
@Override public Component getDetailComponent() { IssueDetailSplitPanel panel = new IssueDetailSplitPanel(); panel.firstTextPane.setText(ste.getSrcText()); panel.lastTextPane.setText(tmxEntry.translation); StyledDocument doc = panel.lastTextPane.getStyledDocument(); for (Token tok : misspelledTokens) { doc.setCharacterAttributes(tok.getOffset(), tok.getLength(), ERROR_STYLE, false); } panel.setMinimumSize(new Dimension(0, panel.firstTextPane.getFont().getSize() * 6)); return panel; }
private Component getSplitPanel() { IssueDetailSplitPanel splitPanel = new IssueDetailSplitPanel(); splitPanel.firstTextPane.setText(ste.getSrcText()); splitPanel.lastTextPane.setText(tmxEntry.translation); StyledDocument doc = splitPanel.firstTextPane.getStyledDocument(); for (Token[] toks : Core.getGlossaryManager().searchSourceMatchTokens(ste, glossaryEntry)) { for (Token tok : toks) { doc.setCharacterAttributes(tok.getOffset(), tok.getLength(), ERROR_STYLE, false); } } splitPanel.setMinimumSize(new Dimension(0, splitPanel.firstTextPane.getFont().getSize() * 6)); return splitPanel; }
@SuppressWarnings("deprecation") public static void createTabs(JTextPane textPane) { int tabSize = AWPrefs.getEditorTabSize(); int charWidth = AWPrefs.getEditorFontSize(); try { charWidth = Toolkit.getDefaultToolkit().getFontMetrics(textPane.getFont()).stringWidth("m"); } catch(Exception e) { // ignore exception } TabStop[] tstops = new TabStop[100]; for(int i = 0; i<100; i++) { tstops[i] = new TabStop(i*tabSize*charWidth); } TabSet tabs = new TabSet(tstops); Style style = textPane.getLogicalStyle(); if(style != null) { StyleConstants.setTabSet(style, tabs); textPane.setLogicalStyle(style); } }