javax.swing.text.StyledEditorKit Java Examples

The following examples show how to use javax.swing.text.StyledEditorKit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ButtonFactory.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private static JButton createFontStyleItalicButton(DrawingEditor editor) {
  JButton button = new JButton();
  button.setIcon(ImageDirectory.getImageIcon("/toolbar/attributeFontItalic.png"));
  button.setText(null);
  button.setToolTipText(BUNDLE.getString("buttonFactory.button_fontStyleItalic.tooltipText"));
  button.setFocusable(false);

  AbstractAction action
      = new AttributeToggler<>(editor,
                               AttributeKeys.FONT_ITALIC,
                               Boolean.TRUE,
                               Boolean.FALSE,
                               new StyledEditorKit.BoldAction());
  action.putValue(ActionUtil.UNDO_PRESENTATION_NAME_KEY,
                  BUNDLE.getString("buttonFactory.action_fontStyleItalic.undo.presentationName"));
  button.addActionListener(action);

  return button;
}
 
Example #2
Source File: ButtonFactory.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private static JButton createFontStyleUnderlineButton(DrawingEditor editor) {
  JButton button = new JButton();
  button.setIcon(ImageDirectory.getImageIcon("/toolbar/attributeFontUnderline.png"));
  button.setText(null);
  button.setToolTipText(BUNDLE.getString("buttonFactory.button_fontStyleUnderline.tooltipText"));
  button.setFocusable(false);

  AbstractAction action
      = new AttributeToggler<>(editor,
                               AttributeKeys.FONT_UNDERLINE,
                               Boolean.TRUE,
                               Boolean.FALSE,
                               new StyledEditorKit.BoldAction());
  action.putValue(ActionUtil.UNDO_PRESENTATION_NAME_KEY,
                  BUNDLE.getString("buttonFactory.action_fontStyleUnderline.undo.presentationName"));
  button.addActionListener(action);

  return button;
}
 
Example #3
Source File: ButtonFactory.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private static JButton createFontStyleBoldButton(DrawingEditor editor) {
  JButton button = new JButton();
  button.setIcon(ImageDirectory.getImageIcon("/toolbar/attributeFontBold.png"));
  button.setText(null);
  button.setToolTipText(BUNDLE.getString("buttonFactory.button_fontStyleBold.tooltipText"));
  button.setFocusable(false);

  AbstractAction action
      = new AttributeToggler<>(editor,
                               AttributeKeys.FONT_BOLD,
                               Boolean.TRUE,
                               Boolean.FALSE,
                               new StyledEditorKit.BoldAction());
  action.putValue(ActionUtil.UNDO_PRESENTATION_NAME_KEY,
                  BUNDLE.getString("buttonFactory.action_fontStyleBold.undo.presentationName"));
  button.addActionListener(action);

  return button;
}
 
Example #4
Source File: HTMLEditor.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/** Creates new form HTMLEditor */
public HTMLEditor(EditableResources res, String htmlText) {
    initComponents();
    this.res = res;
    htmlComponent = new com.codename1.ui.html.HTMLComponent();
    htmlComponent.setBodyText(htmlText, "UTF-8");
    final CodenameOneComponentWrapper wrapper = new CodenameOneComponentWrapper(htmlComponent);
    uiPreview.add(java.awt.BorderLayout.CENTER, wrapper);
    wysiwyg.setText(htmlText);
    source.setText(htmlText);
    Listener l = new Listener();
    wysiwyg.getDocument().addDocumentListener(l);
    source.getDocument().addDocumentListener(l);
    JButton b = jToolBar1.add(new StyledEditorKit.BoldAction());
    b.setText("<html><body><b>B</b></body></html>");
    JButton i = jToolBar1.add(new StyledEditorKit.ItalicAction());
    i.setText("<html><body><i>I</i></body></html>");
    JButton u = jToolBar1.add(new StyledEditorKit.UnderlineAction());
    u.setText("<html><body><u>U</u></body></html>");
    jToolBar1.add(new InsertImageAction());
}
 
Example #5
Source File: HTMLDocumentEditor.java    From egdownloader with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent ae) {
	JEditorPane editor = getEditor(ae);
	if (editor != null) {
		StyledEditorKit kit = getStyledEditorKit(editor);
		MutableAttributeSet attr = kit.getInputAttributes();
		boolean strikeThrough = (StyleConstants.isStrikeThrough(attr)) ? false
				: true;
		SimpleAttributeSet sas = new SimpleAttributeSet();
		StyleConstants.setStrikeThrough(sas, strikeThrough);
		setCharacterAttributes(editor, sas, false);
	}
}
 
Example #6
Source File: HTMLDocumentEditor.java    From egdownloader with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent ae) {
	JEditorPane editor = getEditor(ae);
	if (editor != null) {
		StyledEditorKit kit = getStyledEditorKit(editor);
		MutableAttributeSet attr = kit.getInputAttributes();
		boolean superscript = (StyleConstants.isSuperscript(attr)) ? false
				: true;
		SimpleAttributeSet sas = new SimpleAttributeSet();
		StyleConstants.setSuperscript(sas, superscript);
		setCharacterAttributes(editor, sas, false);
	}
}
 
Example #7
Source File: HTMLDocumentEditor.java    From egdownloader with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent ae) {
	JEditorPane editor = getEditor(ae);
	if (editor != null) {
		StyledEditorKit kit = getStyledEditorKit(editor);
		MutableAttributeSet attr = kit.getInputAttributes();
		boolean subscript = (StyleConstants.isSubscript(attr)) ? false
				: true;
		SimpleAttributeSet sas = new SimpleAttributeSet();
		StyleConstants.setSubscript(sas, subscript);
		setCharacterAttributes(editor, sas, false);
	}
}
 
Example #8
Source File: DetailsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void removeNotify () {
    setEditorKit (new StyledEditorKit ());
    if (hyperlinkListener != null) {
        removeHyperlinkListener (hyperlinkListener);
    }
    scrollPane = null;
    super.removeNotify ();
}
 
Example #9
Source File: bug4242228.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #10
Source File: bug4242228.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    Robot robot = new Robot();
    robot.waitForIdle();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #11
Source File: bug4242228.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #12
Source File: bug4242228.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #13
Source File: bug4242228.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #14
Source File: bug4242228.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #15
Source File: bug4242228.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #16
Source File: bug4242228.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #17
Source File: bug4242228.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #18
Source File: bug4242228.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #19
Source File: bug4242228.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #20
Source File: bug4242228.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}
 
Example #21
Source File: bug4242228.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] argv) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("4242228 Test");

            JScrollPane sourcePane = new JScrollPane();
            final JTextPane htmlEditor = new JTextPane();
            final JTextPane sourceEditor = new JTextPane();
            final JScrollPane editorPane = new JScrollPane();

            tabPane = new JTabbedPane();
            htmlEditor.setText(" ");
            htmlEditor.setEditorKit(new HTMLEditorKit());

            sourceEditor.setText(" ");
            sourceEditor.setEditorKit(new StyledEditorKit());

            frame.setLayout(new BorderLayout());

            editorPane.getViewport().add(htmlEditor);

            tabPane.addTab("Editor", editorPane);
            tabPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabPane.getSelectedComponent() == editorPane) {
                        htmlEditor.setText(sourceEditor.getText());
                    } else {
                        sourceEditor.setText(htmlEditor.getText());
                    }
                }
            });

            sourcePane.getViewport().add(sourceEditor);
            tabPane.addTab("Source", sourcePane);
            tabPane.setTabPlacement(SwingConstants.BOTTOM);
            htmlEditor.setDocument(new HTMLDocument());

            frame.add(tabPane);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                tabPane.setSelectedIndex(i % 2);
            }

            frame.dispose();
        }
    });
}