Code example for JTextComponent

Methods: setBordersetCaretPositionsetText

0
        errorMessagePanel.setBorder(new EmptyBorder(7, 7, 7, 7));
        JScrollPane errorScroller = new JScrollPane(errorMessagePanel);
 
        stackTracePane = new JTextArea(20, 60);
        setErrorMessage(stackTracePane, explanation.getCause());
        stackTracePane.setBorder(new EmptyBorder(7, 7, 7, 7));
        JScrollPane stackTraceScroller = new JScrollPane(stackTracePane);
 
        tabs = new JTabbedPane();
        tabs.addTab("Error", errorScroller);
        tabs.addTab("Stack Trace", stackTraceScroller);
 
        add(tabs, BorderLayout.CENTER);
    } 
 
 
    protected void setErrorMessage(JTextComponent component, Throwable exception) {
 
        final StringWriter stringWriter = new StringWriter();
        final PrintWriter writer = new PrintWriter(stringWriter);
 
        final String message = exception.getMessage();
        if (message != null){
            writer.write(message);
            writer.write("\n\n\n");
        } 
        writer.write("Full Stack Trace\n-----------------------------------------------------------------------------------------\n\n");
 
        exception.printStackTrace(writer);
        writer.flush();
        component.setText(stringWriter.toString());
        component.setCaretPosition(0);
    } 
 
 
    protected JComponent getTabs(){
        return tabs;
Experience pair programming with AI  Get Codota for Java