javax.swing.JTextArea#setCaretPosition ( )源码实例Demo

下面列出了javax.swing.JTextArea#setCaretPosition ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: clearvolume   文件: ClearVolumeTCPClientHelper.java
private void showEditableOptionPane(final String pText,
									final String pTitle,
									final int pMessageType)
{
	final JTextArea ta = new JTextArea(48, 100);
	ta.setText(pText);
	ta.setWrapStyleWord(true);
	ta.setLineWrap(false);
	ta.setCaretPosition(0);
	ta.setEditable(false);

	JOptionPane.showMessageDialog(	null,
									new JScrollPane(ta),
									pTitle,
									pMessageType);
}
 
源代码2 项目: java-ocr-api   文件: PanelLogging.java
private static void logAndScrollToBottom(final JTextArea textArea, final String mesg) {
    if(! SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                logAndScrollToBottom(textArea, mesg);
            }
        });
        return;
    }
    textArea.append(textArea.getText().length() == 0 ? mesg : "\n" + mesg);

    String text = textArea.getText();
    if(text.length() > 2) {
        int lastLinePos = text.lastIndexOf("\n", text.length() - 2);
        if(lastLinePos > 0) {
            textArea.setCaretPosition(lastLinePos + 1); 
        }
    }
}
 
源代码3 项目: netbeans   文件: EditorFindSupportTest.java
/**
 * Test of replaceAll method, of class EditorFindSupport.
 */
@Test
public void testReplaceAll2() throws Exception {
    final Map<String, Object> props = new HashMap<>();
    props.put(EditorFindSupport.FIND_WHAT, "ahoj");
    props.put(EditorFindSupport.FIND_REPLACE_WITH, "xxx");
    props.put(EditorFindSupport.FIND_HIGHLIGHT_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_INC_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_BACKWARD_SEARCH, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_WRAP_SEARCH, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_MATCH_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_SMART_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_REG_EXP, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_HISTORY, new Integer(30));

    final EditorFindSupport instance = EditorFindSupport.getInstance();
    JTextArea ta = new JTextArea("0123456789 ahoj ahoj svete");
    ta.setCaretPosition(15);
    instance.replaceAllImpl(props, ta);
    assertEquals("0123456789 ahoj xxx svete", ta.getText());
}
 
源代码4 项目: netbeans   文件: EditorFindSupportTest.java
/**
 * Test of replaceAll method, of class EditorFindSupport.
 */
@Test
public void testReplaceAll7() throws Exception {
    final Map<String, Object> props = new HashMap<>();
    props.put(EditorFindSupport.FIND_WHAT, "ahoj");
    props.put(EditorFindSupport.FIND_REPLACE_WITH, "xxx");
    props.put(EditorFindSupport.FIND_HIGHLIGHT_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_INC_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_BACKWARD_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_WRAP_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_MATCH_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_SMART_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_REG_EXP, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_HISTORY, new Integer(30));

    final EditorFindSupport instance = EditorFindSupport.getInstance();
    JTextArea ta = new JTextArea("0123456789 ahojahojahoj svete");
    ta.setCaretPosition(ta.getText().length()-1);
    instance.replaceAllImpl(props, ta);
    assertEquals("0123456789 xxxxxxxxx svete", ta.getText());
}
 
源代码5 项目: netbeans   文件: EditorFindSupportTest.java
/**
 * Test of replaceAll method, of class EditorFindSupport.
 */
@Test
public void testReplaceAll9() throws Exception {
    final Map<String, Object> props = new HashMap<>();
    props.put(EditorFindSupport.FIND_WHAT, "a");
    props.put(EditorFindSupport.FIND_REPLACE_WITH, "b");
    props.put(EditorFindSupport.FIND_HIGHLIGHT_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_INC_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_BACKWARD_SEARCH, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_WRAP_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_MATCH_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_SMART_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_REG_EXP, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_HISTORY, new Integer(30));

    final EditorFindSupport instance = EditorFindSupport.getInstance();
    JTextArea ta = new JTextArea("aa");
    ta.setCaretPosition(1);
    instance.replaceAllImpl(props, ta);
    assertEquals("bb", ta.getText());
}
 
源代码6 项目: javamelody   文件: Utilities.java
/**
 * Affiche un texte scrollable non éditable dans une popup.
 * @param component Parent
 * @param title Titre de la popup
 * @param text Texte
 */
public static void showTextInPopup(Component component, String title, String text) {
	final JTextArea textArea = new JTextArea();
	textArea.setText(text);
	textArea.setEditable(false);
	textArea.setCaretPosition(0);
	// background nécessaire avec la plupart des look and feels dont Nimbus,
	// sinon il reste blanc malgré editable false
	textArea.setBackground(Color.decode("#E6E6E6"));
	final JScrollPane scrollPane = new JScrollPane(textArea);

	final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 5));
	final MButton clipBoardButton = new MButton(
			I18NAdapter.getString("Copier_dans_presse-papiers"));
	clipBoardButton.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			textArea.selectAll();
			textArea.copy();
			textArea.setCaretPosition(0);
		}
	});
	buttonPanel.setOpaque(false);
	buttonPanel.add(clipBoardButton);

	final Window window = SwingUtilities.getWindowAncestor(component);
	final JDialog dialog = new JDialog((JFrame) window, title, true);
	final JPanel contentPane = new JPanel(new BorderLayout());
	contentPane.add(scrollPane, BorderLayout.CENTER);
	contentPane.add(buttonPanel, BorderLayout.SOUTH);
	dialog.setContentPane(contentPane);
	dialog.pack();
	dialog.setLocationRelativeTo(window);
	dialog.setVisible(true);
}
 
源代码7 项目: procamtracker   文件: MainFrame.java
private void readmeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readmeMenuItemActionPerformed
    try {
        JTextArea textArea = new JTextArea();
        Font font = textArea.getFont();
        textArea.setFont(new Font("Monospaced", font.getStyle(), font.getSize()));
        textArea.setEditable(false);

        String text = "";
        BufferedReader r = new BufferedReader(new FileReader(
                myDirectory + File.separator + "../README.md"));
        String line;
        while ((line = r.readLine()) != null) {
            text += line + '\n';
        }

        textArea.setText(text);
        textArea.setCaretPosition(0);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setColumns(80);

        // stuff it in a scrollpane with a controlled size.
        JScrollPane scrollPane = new JScrollPane(textArea);
        Dimension dim = textArea.getPreferredSize();
        dim.height = dim.width*50/80;
        scrollPane.setPreferredSize(dim);

        // pass the scrollpane to the joptionpane.
        JDialog dialog = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE).
                createDialog(this, "README");
        dialog.setResizable(true);
        dialog.setModalityType(ModalityType.MODELESS);
        dialog.setVisible(true);
    } catch (Exception ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
源代码8 项目: pentaho-reporting   文件: AboutDialog.java
/**
 * Creates a panel showing the licence.
 *
 * @return a panel.
 */
private JPanel createLicencePanel() {

  final JPanel licencePanel = new JPanel( new BorderLayout() );
  final JTextArea area = new JTextArea( this.licence );
  area.setLineWrap( true );
  area.setWrapStyleWord( true );
  area.setCaretPosition( 0 );
  area.setEditable( false );
  licencePanel.add( new JScrollPane( area ) );
  return licencePanel;

}
 
源代码9 项目: netbeans   文件: EditorFindSupportTest.java
/**
 * Test of replaceAll method, of class EditorFindSupport for regressions in #165497.
 */
@Test
public void testReplaceAllFinishes_165497_e() throws Exception {
    final Map<String, Object> props = new HashMap<>();
    props.put(EditorFindSupport.FIND_WHAT, "a");
    props.put(EditorFindSupport.FIND_REPLACE_WITH, "a");
    props.put(EditorFindSupport.FIND_HIGHLIGHT_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_INC_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_BACKWARD_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_WRAP_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_MATCH_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_SMART_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_REG_EXP, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_HISTORY, new Integer(30));

    final EditorFindSupport instance = EditorFindSupport.getInstance();
    final boolean [] finished = new boolean[1];
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            JTextArea ta = new JTextArea("aaaa");
            ta.setCaretPosition(2);
            instance.replaceAllImpl(props, ta);
            finished[0] = true;
        }
    });
    t.start();
    Thread.sleep(2000);
    if (!finished[0]) {
        t.stop();
    }
    assertTrue(finished[0]);
}
 
源代码10 项目: procamcalib   文件: MainFrame.java
private void readmeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readmeMenuItemActionPerformed
    try {
        JTextArea textArea = new JTextArea();
        Font font = textArea.getFont();
        textArea.setFont(new Font("Monospaced", font.getStyle(), font.getSize()));
        textArea.setEditable(false);

        String text = "";
        BufferedReader r = new BufferedReader(new FileReader(
                myDirectory + File.separator + "../README.md"));
        String line;
        while ((line = r.readLine()) != null) {
            text += line + '\n';
        }

        textArea.setText(text);
        textArea.setCaretPosition(0);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setColumns(80);

        // stuff it in a scrollpane with a controlled size.
        JScrollPane scrollPane = new JScrollPane(textArea);
        Dimension dim = textArea.getPreferredSize();
        dim.height = dim.width*50/80;
        scrollPane.setPreferredSize(dim);

        // pass the scrollpane to the joptionpane.
        JDialog dialog = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE).
                createDialog(this, "README");
        dialog.setResizable(true);
        dialog.setModalityType(ModalityType.MODELESS);
        dialog.setVisible(true);
    } catch (Exception ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
源代码11 项目: settlers-remake   文件: ExceptionDialog.java
/**
 * Prepare the contents
 * 
 * @param e
 *            Exception
 * @param description
 *            Description
 * @param t
 *            Thread
 * @return Panel with all iformation
 */
private JPanel prepareContents(Throwable e, String description, Thread t) {
	JPanel p = new JPanel();
	p.setLayout(new BorderLayout());
	JTextArea txt = new JTextArea(10, 40);

	StringBuilder b = new StringBuilder();

	b.append("```\n");
	b.append(description);
	b.append("\n---\n== Thread ==");
	b.append("\nname: ");
	b.append(t.getName());
	b.append("\nID: ");
	b.append(t.getId());
	b.append("\n---\n== Exception ==");
	b.append("\nclass: ");
	b.append(e.getClass().getName());
	b.append("\nmessage: ");
	b.append(e.getMessage());
	b.append("\nmessage: ");
	b.append(e.getMessage());
	b.append("\nstacktrace:\n");

	StringWriter errors = new StringWriter();
	e.printStackTrace(new PrintWriter(errors));
	b.append(errors.toString());

	b.append("```\n");

	errorString = b.toString();
	txt.setText(b.toString());
	txt.setCaretPosition(0);

	p.add(new JScrollPane(txt), BorderLayout.CENTER);
	return p;
}
 
源代码12 项目: netbeans   文件: EditorFindSupportTest.java
@Test
public void testReplaceFind() throws Exception {
    final Map<String, Object> props = new HashMap<>();
    props.put(EditorFindSupport.FIND_WHAT, "a");
    props.put(EditorFindSupport.FIND_REPLACE_WITH, "b");
    props.put(EditorFindSupport.FIND_HIGHLIGHT_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_INC_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_BACKWARD_SEARCH, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_WRAP_SEARCH, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_MATCH_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_SMART_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_REG_EXP, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_HISTORY, new Integer(30));
    
    final EditorFindSupport instance = EditorFindSupport.getInstance();
    JTextArea ta = new JTextArea("aaaa");
    ta.setCaretPosition(0);
    instance.replaceImpl(props, false, ta);
    instance.findReplaceImpl(null, props, false, ta);
    assertEquals("baaa", ta.getText());
    instance.replaceImpl(props, false, ta);
    instance.findReplaceImpl(null, props, false, ta);
    assertEquals("bbaa", ta.getText());
    instance.replaceImpl(props, false, ta);
    instance.findReplaceImpl(null, props, false, ta);
    assertEquals("bbba", ta.getText());
}
 
源代码13 项目: netbeans   文件: EditorFindSupportTest.java
@Test
public void testReplaceFindFocused() throws Exception {
    final Map<String, Object> props = new HashMap<>();
    props.put(EditorFindSupport.FIND_WHAT, "a");
    props.put(EditorFindSupport.FIND_REPLACE_WITH, "b");
    props.put(EditorFindSupport.FIND_HIGHLIGHT_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_INC_SEARCH, Boolean.TRUE);
    props.put(EditorFindSupport.FIND_BACKWARD_SEARCH, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_WRAP_SEARCH, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_MATCH_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_SMART_CASE, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_REG_EXP, Boolean.FALSE);
    props.put(EditorFindSupport.FIND_HISTORY, new Integer(30));
    
    final EditorFindSupport instance = EditorFindSupport.getInstance();
    JTextArea ta = new JTextArea("aaaa");
    ta.setCaretPosition(0);
    instance.setFocusedTextComponent(ta);
    instance.replace(props, false);
    instance.find(props, false);
    assertEquals("baaa", ta.getText());
    instance.replace(props, false);
    instance.find(props, false);
    assertEquals("bbaa", ta.getText());
    instance.replace(props, false);
    instance.find(props, false);
    assertEquals("bbba", ta.getText());
}
 
源代码14 项目: openvisualtraceroute   文件: LicenseDialog.java
/**
 * Constructor
 */
public LicenseDialog(final Window parent) {
	super(parent, Resources.getLabel("license.button"), ModalityType.APPLICATION_MODAL);
	getContentPane().add(createHeaderPanel(false, null), BorderLayout.NORTH);
	final JTextArea license = new JTextArea(30, 50);
	license.setEditable(false);
	// read the license file and add its content to the JTextArea
	for (final String line : Util.readUTF8File(Resources.class.getResourceAsStream("/" + Resources.RESOURCE_PATH + "/License.txt"))) {
		license.append("   " + line + "\n");
	}
	// scroll to the top of the JTextArea
	license.setCaretPosition(0);
	// the all thing in a ScrollPane
	final JScrollPane scroll = new JScrollPane(license);
	getContentPane().add(scroll, BorderLayout.CENTER);
	final JPanel donatePanel = new JPanel(new BorderLayout(5, 10));
	final JLabel donate = new JLabel(Resources.getLabel("donate"));
	donatePanel.add(donate, BorderLayout.NORTH);
	final JPanel center = new JPanel();
	center.setLayout(new FlowLayout());
	center.add(new JLabel(Resources.getImageIcon("donate.png")));
	center.add(new HyperlinkLabel(Resources.getLabel("donate.label"), Env.INSTANCE.getDonateUrl()));
	donatePanel.add(center, BorderLayout.CENTER);
	final JButton close = new JButton(Resources.getLabel("close.button"));
	close.addActionListener(e -> LicenseDialog.this.dispose());
	donatePanel.add(close, BorderLayout.SOUTH);
	getContentPane().add(donatePanel, BorderLayout.SOUTH);
	SwingUtilities4.setUp(this);
	getRootPane().registerKeyboardAction(e -> dispose(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
}
 
源代码15 项目: netbeans   文件: ToStringGeneratorTest.java
public void testToStringWithPlusOperator() throws Exception {
    FileObject javaFile = FileUtil.createData(fo, "NewClass.java");
    String what1 = ""
            + "public class NewClass {\n"
            + "    private final String test1 = \"test\";\n"
            + "    private final String test2 = \"test\";\n"
            + "    private final String test3 = \"test\";\n";

    String what2 = ""
            + "\n"
            + "}";
    String what = what1 + what2;
    GeneratorUtilsTest.writeIntoFile(javaFile, what);

    JavaSource javaSource = JavaSource.forFileObject(javaFile);
    assertNotNull("Created", javaSource);

    Document doc = getDocuemnt(javaFile);

    final JTextArea component = new JTextArea(doc);
    component.setCaretPosition(what1.length());

    class Task implements org.netbeans.api.java.source.Task<CompilationController> {

        private ToStringGenerator generator;

        @Override
        public void run(CompilationController controller) throws Exception {
            controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
            Element typeElement = controller.getElements().getTypeElement("NewClass");
            generator = ToStringGenerator.createToStringGenerator(component, controller, typeElement, false);
        }

        public void post() throws Exception {
            assertNotNull("Created", generator);

            assertEquals("Three fields", 3, generator.getDescription().getSubs().size());
            assertEquals("test1 field selected", true, generator.getDescription().getSubs().get(0).isSelected());
            assertEquals("test2 field selected", true, generator.getDescription().getSubs().get(1).isSelected());
            assertEquals("test3 field selected", true, generator.getDescription().getSubs().get(2).isSelected());
            assertEquals("Don't use StringBuilder", false, generator.useStringBuilder());
        }
    }
    final Task task = new Task();

    javaSource.runUserActionTask(task, false);
    task.post();

    SwingUtilities.invokeAndWait(() -> task.generator.invoke());

    Document document = component.getDocument();
    String text = document.getText(0, document.getLength());
    String expected = ""
            + "public class NewClass {\n"
            + "    private final String test1 = \"test\";\n"
            + "    private final String test2 = \"test\";\n"
            + "    private final String test3 = \"test\";\n"
            + "\n"
            + "    @Override\n"
            + "    public String toString() {\n"
            + "        return \"NewClass{\" + \"test1=\" + test1 + \", test2=\" + test2 + \", test3=\" + test3 + '}';\n"
            + "    }\n"
            + "\n"
            + "}";
    assertEquals(expected, text);
}
 
源代码16 项目: netbeans   文件: ToStringGeneratorTest.java
public void testToStringExists() throws Exception {
    FileObject javaFile = FileUtil.createData(fo, "NewClass.java");
    String what1 = ""
            + "public class NewClass {\n"
            + "    private final String test1 = \"test\";\n"
            + "    private final String test2 = \"test\";\n"
            + "    private final String test3 = \"test\";\n";

    String what2 = ""
            + "\n"
            + "    @Override\n"
            + "    public String toString() {\n"
            + "        StringBuilder sb = new StringBuilder();\n"
            + "        sb.append(\"NewClass{\");\n"
            + "        sb.append(\"test1=\").append(test1);\n"
            + "        sb.append(\", \");\n"
            + "        sb.append(\"test2=\").append(test2);\n"
            + "        sb.append(\", \");\n"
            + "        sb.append(\"test3=\").append(test3);\n"
            + "        sb.append('}');\n"
            + "        return sb.toString();\n"
            + "    }\n"
            + "\n"
            + "}";
    String what = what1 + what2;
    GeneratorUtilsTest.writeIntoFile(javaFile, what);

    JavaSource javaSource = JavaSource.forFileObject(javaFile);
    assertNotNull("Created", javaSource);

    Document doc = getDocuemnt(javaFile);

    final JTextArea component = new JTextArea(doc);
    component.setCaretPosition(what1.length());

    class Task implements org.netbeans.api.java.source.Task<CompilationController> {

        private ToStringGenerator generator;

        @Override
        public void run(CompilationController controller) throws Exception {
            controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
            Element typeElement = controller.getElements().getTypeElement("NewClass");
            generator = ToStringGenerator.createToStringGenerator(component, controller, typeElement, true);
        }

        public void post() throws Exception {
            assertNull("Not created", generator);
        }
    }
    final Task task = new Task();

    javaSource.runUserActionTask(task, false);
    task.post();
}
 
源代码17 项目: visualvm   文件: GeneralPropertiesProvider.java
private static void updateProperties(JTextArea textArea, String hostname, String ip) {
    String dnsName = NbBundle.getMessage(GeneralPropertiesProvider.class, "LBL_DnsName"); // NOI18N
    String ipAddress = NbBundle.getMessage(GeneralPropertiesProvider.class, "LBL_IpAddress"); // NOI18N
    textArea.setText(dnsName + " " + hostname + "\n" + ipAddress + " " + ip); // NOI18N
    textArea.setCaretPosition(0);
}
 
源代码18 项目: azure-devops-intellij   文件: EULADialog.java
private EULADialog(@Nullable Project project, @NotNull String title, @Nullable String eulaText, boolean isPlainText, OnEulaAccepted onAccept) {
    super(project);
    this.onAccept = onAccept;
    myEulaTextFound = eulaText != null;

    JComponent component;
    if (isPlainText) {
        JTextArea textArea = new JTextArea();
        textArea.setText(eulaText);
        textArea.setMinimumSize(null);
        textArea.setEditable(false);
        textArea.setCaretPosition(0);
        textArea.setBackground(null);
        textArea.setBorder(JBUI.Borders.empty());

        component = textArea;
    } else {
        JEditorPane editor = new JEditorPane();
        editor.setContentType("text/html");
        editor.getDocument().putProperty("IgnoreCharsetDirective", Boolean.TRUE); // work around <meta> tag
        editor.setText(eulaText);
        editor.setEditable(false);
        editor.setCaretPosition(0);
        editor.setMinimumSize(null);
        editor.setBorder(JBUI.Borders.empty());

        component = editor;
    }

    myScrollPane = new JBScrollPane(component);
    myScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

    setModal(true);
    setTitle(title);

    setOKButtonText("Accept");
    getOKAction().putValue(DEFAULT_ACTION, null);

    setCancelButtonText("Decline");
    getCancelAction().putValue(DEFAULT_ACTION, Boolean.TRUE);

    init();
}
 
源代码19 项目: SIMVA-SoS   文件: Main.java
public static void consolePrint(JTextArea console, String text) {
    console.append(text);
    console.setCaretPosition(console.getDocument().getLength());
    console.requestFocus();
}
 
源代码20 项目: portecle   文件: DViewPEM.java
/**
 * Initialize the dialog's GUI components.
 *
 * @throws CryptoException A problem was encountered getting the object's PEM encoding
 */
private void initComponents()
    throws CryptoException
{
	if (m_pem == null)
	{
		StringWriter encoded = new StringWriter();
		try (JcaPEMWriter pw = new JcaPEMWriter(encoded))
		{
			pw.writeObject(m_object);
		}
		catch (IOException e)
		{
			throw new CryptoException(RB.getString("DViewPEM.exception.message"), e);
		}
		m_pem = encoded.toString();
	}

	JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));

	JButton jbOK = getOkButton(true);

	final JButton jbSave = new JButton(RB.getString("DViewPEM.jbSave.text"));
	jbSave.setMnemonic(RB.getString("DViewPEM.jbSave.mnemonic").charAt(0));
	if (m_chooser == null || m_pem == null)
	{
		jbSave.setEnabled(false);
	}
	else
	{
		jbSave.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent evt)
			{
				savePressed();
			}
		});
	}

	jpButtons.add(jbOK);
	jpButtons.add(jbSave);

	JPanel jpPEM = new JPanel(new BorderLayout());
	jpPEM.setBorder(new EmptyBorder(5, 5, 5, 5));

	// Load text area with the PEM encoding
	JTextArea jtaPEM = new JTextArea(m_pem);
	jtaPEM.setCaretPosition(0);
	jtaPEM.setEditable(false);
	jtaPEM.setFont(new Font(Font.MONOSPACED, Font.PLAIN, jtaPEM.getFont().getSize()));

	JScrollPane jspPEM = new JScrollPane(jtaPEM, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
	    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
	jspPEM.setPreferredSize(new Dimension(500, 300));
	jpPEM.add(jspPEM, BorderLayout.CENTER);

	getContentPane().add(jpPEM, BorderLayout.CENTER);
	getContentPane().add(jpButtons, BorderLayout.SOUTH);

	getRootPane().setDefaultButton(jbOK);

	initDialog();

	setResizable(true);
	jbOK.requestFocusInWindow();
}