List of usage examples for javax.swing JTextPane JTextPane
public JTextPane()
JTextPane
. From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = (StyledDocument) textPane.getDocument(); // Create a style object and then set the style attributes Style style = doc.addStyle("StyleName", null); StyleConstants.setForeground(style, Color.white); // Append to document doc.insertString(doc.getLength(), "Some Text", style); }
From source file:Main.java
public static void main(String[] args) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); Style style = textPane.addStyle("I'm a Style", null); StyleConstants.setForeground(style, Color.red); doc.insertString(doc.getLength(), "BLAH ", style); StyleConstants.setForeground(style, Color.blue); doc.insertString(doc.getLength(), "BLEH", style); }
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 w w w . j ava 2 s .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:ListActionsJTextPane.java
public static void main(String args[]) { JTextComponent component = new JTextPane(); // Process action list Action actions[] = component.getActions(); // Define comparator to sort actions Comparator<Action> comparator = new Comparator<Action>() { public int compare(Action a1, Action a2) { String firstName = (String) a1.getValue(Action.NAME); String secondName = (String) a2.getValue(Action.NAME); return firstName.compareTo(secondName); }/*from w ww .j a v a2s . c o m*/ }; Arrays.sort(actions, comparator); int count = actions.length; System.out.println("Count: " + count); for (int i = 0; i < count; i++) { System.out.printf("%28s : %s\n", actions[i].getValue(Action.NAME), actions[i].getClass().getName()); } }
From source file:Main.java
public static void main(String[] args) { final JTextPane pane = new JTextPane(); pane.setText("Some text"); JButton buttonButton = new JButton("Insert label"); buttonButton.addActionListener(e -> { JLabel label = new JLabel("label"); label.setAlignmentY(0.85f);/*from www .j a v a2s .c om*/ pane.insertComponent(label); }); JPanel panel = new JPanel(new BorderLayout()); panel.add(buttonButton, BorderLayout.SOUTH); panel.add(pane, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JTextPane tp = new JTextPane(); JButton withFocus = new JButton("Select with focus"); withFocus.addActionListener(e -> { tp.selectAll();/*from w ww . ja v a2s. c o m*/ tp.requestFocus(); }); JButton withOutFocus = new JButton("Select without focus"); withFocus.addActionListener(e -> tp.selectAll()); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(tp)); JPanel panel = new JPanel(); panel.add(withFocus); panel.add(withOutFocus); frame.add(panel, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane newsTextPane = new JTextPane(); newsTextPane.setEditable(false);// www.j a va2 s .c om JScrollPane scrollPane = new JScrollPane(newsTextPane); frame.add(scrollPane); frame.setSize(300, 250); frame.setVisible(true); System.out.println("Height : " + scrollPane.getViewport().getSize().height + "\nWidth :" + scrollPane.getViewport().getSize().width); }
From source file:Main.java
public static void main(String[] args) { JTextPane jTextPane = new JTextPane(); JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack();//from w w w .j a v a2 s.c o m frame.setVisible(true); JButton btnGetSelectedText = new JButton("Get selected text"); btnGetSelectedText.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println(jTextPane.getSelectedText()); } }); frame.getContentPane().add(jTextPane, BorderLayout.NORTH); frame.getContentPane().add(btnGetSelectedText, BorderLayout.SOUTH); }
From source file:Main.java
public static void main(String[] argv) { JTextPane textPane = new JTextPane(); List list = new ArrayList(); TabStop[] tstops = (TabStop[]) list.toArray(new TabStop[0]); TabSet tabs = new TabSet(tstops); Style style = textPane.getLogicalStyle(); StyleConstants.setTabSet(style, tabs); textPane.setLogicalStyle(style);/*from ww w . j a v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane c1 = new JTextPane(); JTextPane c2 = new JTextPane(); StyleContext styleContext = new StyleContext(); c1.setDocument(new DefaultStyledDocument(styleContext)); c2.setDocument(new DefaultStyledDocument(styleContext)); Style style = c1.addStyle("style name", null); StyleConstants.setForeground(style, Color.red); style = c2.getStyle("style name"); StyleConstants.setBold(style, true); }