Example usage for javax.swing JTextArea setEditable

List of usage examples for javax.swing JTextArea setEditable

Introduction

In this page you can find the example usage for javax.swing JTextArea setEditable.

Prototype

@BeanProperty(description = "specifies if the text can be edited")
public void setEditable(boolean b) 

Source Link

Document

Sets the specified boolean to indicate whether or not this TextComponent should be editable.

Usage

From source file:Main.java

public static final Component getLabelComponent(String text, int rows, int cols) {
    JTextArea txt = new JTextArea(text, 10, 80);
    //txt.setColumns(80);
    txt.setWrapStyleWord(true);/*from ww w  .ja v  a2 s.c o  m*/
    txt.setLineWrap(true);
    txt.setOpaque(false);
    txt.setEditable(false);
    //txt.setEnabled(false);
    //txt.setFont(FontLoaderUtils.getOrLoadACompatibleFont(text,txt.getFont()));//UIManager.getFont("Label.font")));
    return new JScrollPane(txt);
}

From source file:Main.java

/**
 * Configures a text area to display as if it were a label.  This can be useful if you know how many columns
 * you want a label to be./*w w w.  jav  a  2 s  .  co m*/
 * @param textArea The text area to configure as a JLabel.
 */
public static void configureAsLabel(JTextArea textArea) {
    textArea.setOpaque(false);
    Font textFont = UIManager.getFont("Label.font");
    textArea.setFont(textFont);
    textArea.setBorder(null);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setEditable(false);
}

From source file:com.diversityarrays.kdxplore.KDXplore.java

private static void doStaticInitChecks(boolean quiet) {
    try {/*from  w  ww  . ja  v  a2  s. c  o m*/
        KdxConstants.runStaticInitChecks(true, quiet);
    } catch (RuntimeException e) {
        String msg = e.getClass().getName() + "\n" + e.getMessage(); //$NON-NLS-1$
        // deliberately NOT using MsgBox here
        JTextArea ta = new JTextArea(msg);
        ta.setEditable(false);
        JOptionPane.showMessageDialog(null, new JScrollPane(ta), "KDXplore Initialisation Error", //$NON-NLS-1$
                JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }
}

From source file:com.heliosdecompiler.bootstrapper.Bootstrapper.java

private static HeliosData loadHelios() throws IOException {
    System.out.println("Finding Helios implementation");

    HeliosData data = new HeliosData();

    boolean needsToDownload = !IMPL_FILE.exists();
    if (!needsToDownload) {
        try (JarFile jarFile = new JarFile(IMPL_FILE)) {
            ZipEntry entry = jarFile.getEntry("META-INF/MANIFEST.MF");
            if (entry == null) {
                needsToDownload = true;/* w w w  . j  a v  a  2s  .c om*/
            } else {
                Manifest manifest = new Manifest(jarFile.getInputStream(entry));
                String ver = manifest.getMainAttributes().getValue("Implementation-Version");
                try {
                    data.buildNumber = Integer.parseInt(ver);
                    data.version = manifest.getMainAttributes().getValue("Version");
                    data.mainClass = manifest.getMainAttributes().getValue("Main-Class");
                } catch (NumberFormatException e) {
                    needsToDownload = true;
                }
            }
        } catch (IOException e) {
            needsToDownload = true;
        }
    }
    if (needsToDownload) {
        URL latestJar = new URL(LATEST_JAR);
        System.out.println("Downloading latest Helios implementation");

        FileOutputStream out = new FileOutputStream(IMPL_FILE);
        HttpURLConnection connection = (HttpURLConnection) latestJar.openConnection();
        if (connection.getResponseCode() == 200) {
            int contentLength = connection.getContentLength();
            if (contentLength > 0) {
                InputStream stream = connection.getInputStream();
                byte[] buffer = new byte[1024];
                int amnt;
                AtomicInteger total = new AtomicInteger();
                AtomicBoolean stop = new AtomicBoolean(false);

                Thread progressBar = new Thread() {
                    public void run() {
                        JPanel panel = new JPanel();
                        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

                        JLabel label = new JLabel();
                        label.setText("Downloading latest Helios build");
                        panel.add(label);

                        GridLayout layout = new GridLayout();
                        layout.setColumns(1);
                        layout.setRows(3);
                        panel.setLayout(layout);
                        JProgressBar pbar = new JProgressBar();
                        pbar.setMinimum(0);
                        pbar.setMaximum(100);
                        panel.add(pbar);

                        JTextArea textArea = new JTextArea(1, 3);
                        textArea.setOpaque(false);
                        textArea.setEditable(false);
                        textArea.setText("Downloaded 00.00MB/00.00MB");
                        panel.add(textArea);

                        JFrame frame = new JFrame();
                        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                        frame.setContentPane(panel);
                        frame.pack();
                        frame.setLocationRelativeTo(null);
                        frame.setVisible(true);

                        while (!stop.get()) {
                            SwingUtilities.invokeLater(
                                    () -> pbar.setValue((int) (100.0 * total.get() / contentLength)));

                            textArea.setText("Downloaded " + bytesToMeg(total.get()) + "MB/"
                                    + bytesToMeg(contentLength) + "MB");
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException ignored) {
                            }
                        }
                        frame.dispose();
                    }
                };
                progressBar.start();

                while ((amnt = stream.read(buffer)) != -1) {
                    out.write(buffer, 0, amnt);
                    total.addAndGet(amnt);
                }
                stop.set(true);
                return loadHelios();
            } else {
                throw new IOException("Content-Length set to " + connection.getContentLength());
            }
        } else if (connection.getResponseCode() == 404) { // Most likely bootstrapper is out of date
            throw new RuntimeException("Bootstrapper out of date!");
        } else {
            throw new IOException(connection.getResponseCode() + ": " + connection.getResponseMessage());
        }
    }

    return data;
}

From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java

public static void showErrorDialog(Component parent, String title, String textMessage, Throwable cause) {
    final String stacktrace;
    if (cause == null) {
        stacktrace = null;/* ww  w .j  a  v  a  2s. c  o m*/
    } else {
        final ByteArrayOutputStream stackTrace = new ByteArrayOutputStream();
        cause.printStackTrace(new PrintStream(stackTrace));
        stacktrace = new String(stackTrace.toByteArray());
    }

    final JDialog dialog = new JDialog((Window) null, title);

    dialog.setModal(true);

    final JTextArea message = createMultiLineLabel(textMessage);
    final DialogResult[] outcome = { DialogResult.CANCEL };

    final JButton okButton = new JButton("Ok");
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.YES;
            dialog.dispose();
        }
    });

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(okButton);

    final JPanel messagePanel = new JPanel();
    messagePanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    cnstrs.weightx = 1;
    cnstrs.weighty = 0.1;
    cnstrs.gridheight = 1;
    messagePanel.add(message, cnstrs);

    if (stacktrace != null) {
        final JTextArea createMultiLineLabel = new JTextArea(stacktrace);

        createMultiLineLabel.setBackground(null);
        createMultiLineLabel.setEditable(false);
        createMultiLineLabel.setBorder(null);
        createMultiLineLabel.setLineWrap(false);
        createMultiLineLabel.setWrapStyleWord(false);

        final JScrollPane pane = new JScrollPane(createMultiLineLabel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        cnstrs = constraints(0, 1, true, true, GridBagConstraints.BOTH);
        cnstrs.weightx = 1.0;
        cnstrs.weighty = 0.9;
        cnstrs.gridwidth = GridBagConstraints.REMAINDER;
        cnstrs.gridheight = GridBagConstraints.REMAINDER;
        messagePanel.add(pane, cnstrs);
    }

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, true, false, GridBagConstraints.BOTH);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 1.0;
    cnstrs.insets = new Insets(5, 2, 5, 2); // top,left,bottom,right           
    panel.add(messagePanel, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(0, 2, 10, 2); // top,left,bottom,right      
    panel.add(buttonPanel, cnstrs);

    dialog.getContentPane().add(panel);

    dialog.setMinimumSize(new Dimension(600, 400));
    dialog.setPreferredSize(new Dimension(600, 400));
    dialog.setMaximumSize(new Dimension(600, 400));

    dialog.pack();
    dialog.setVisible(true);
}

From source file:com.clank.launcher.swing.SwingHelper.java

/**
 * Show a message dialog using/*w w w .ja v  a 2  s  .c om*/
 * {@link javax.swing.JOptionPane#showMessageDialog(java.awt.Component, Object, String, int)}.
 *
 * <p>The dialog will be shown from the Event Dispatch Thread, regardless of the
 * thread it is called from. In either case, the method will block until the
 * user has closed the dialog (or dialog creation fails for whatever reason).</p>
 *
 * @param parentComponent the frame from which the dialog is displayed, otherwise
 *                        null to use the default frame
 * @param message the message to display
 * @param title the title string for the dialog
 * @param messageType see {@link javax.swing.JOptionPane#showMessageDialog(java.awt.Component, Object, String, int)}
 *                    for available message types
 */
public static void showMessageDialog(final Component parentComponent, @NonNull final String message,
        @NonNull final String title, final String detailsText, final int messageType) {

    if (SwingUtilities.isEventDispatchThread()) {
        // To force the label to wrap, convert the message to broken HTML
        String htmlMessage = "<html><div style=\"width: 250px\">" + htmlEscape(message);

        JPanel panel = new JPanel(new BorderLayout(0, detailsText != null ? 20 : 0));

        // Add the main message
        panel.add(new JLabel(htmlMessage), BorderLayout.NORTH);

        // Add the extra details
        if (detailsText != null) {
            JTextArea textArea = new JTextArea(_("errors.reportErrorPreface") + detailsText);
            JLabel tempLabel = new JLabel();
            textArea.setFont(tempLabel.getFont());
            textArea.setBackground(tempLabel.getBackground());
            textArea.setTabSize(2);
            textArea.setEditable(false);
            textArea.setComponentPopupMenu(TextFieldPopupMenu.INSTANCE);

            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new Dimension(350, 120));
            panel.add(scrollPane, BorderLayout.CENTER);
        }

        JOptionPane.showMessageDialog(parentComponent, panel, title, messageType);
    } else {
        // Call method again from the Event Dispatch Thread
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    showMessageDialog(parentComponent, message, title, detailsText, messageType);
                }
            });
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:de.ipk_gatersleben.ag_nw.graffiti.services.GUIhelper.java

public static Component getHelpTextComponent(String plainText, String title, String helpTopic) {
    JPanel result = new JPanel();
    plainText = plainText.replaceAll("<br>", "\n");
    plainText = plainText.replaceAll("<html>", "");
    plainText = plainText.replaceAll("<small>", "");
    FolderPanel fp = new FolderPanel(title, false, false, false,
            JLabelJavaHelpLink.getHelpActionListener(helpTopic));
    JTextArea helpText = new JTextArea();
    helpText.setLineWrap(true);/*from  w  w  w .  j a  v a  2  s .c o  m*/
    helpText.setWrapStyleWord(true);
    helpText.setText(plainText);
    helpText.setEditable(false);
    fp.addGuiComponentRow(new JLabel(""), helpText, false);
    fp.layoutRows();
    fp.setFrameColor(Color.LIGHT_GRAY, Color.WHITE, 1, 5);

    double border = 2;
    double topBorder = 12;
    double[][] size = { { border, TableLayoutConstants.FILL, border }, // Columns
            { topBorder, TableLayoutConstants.PREFERRED, border } }; // Rows
    result.setLayout(new TableLayout(size));
    result.add(fp, "1,1");
    return result;
}

From source file:Main.java

public void build() {
    setSize(600, 600);/*from   www .  ja  v a 2  s.c om*/
    JTextPane textPane = new JTextPane();

    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(300, 300));

    JTextArea changeLog = new JTextArea(5, 30);
    changeLog.setEditable(false);
    JScrollPane scrollPaneForLog = new JScrollPane(changeLog);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog);
    splitPane.setOneTouchExpandable(true);

    JPanel statusPane = new JPanel(new GridLayout(1, 1));
    JLabel caretListenerLabel = new JLabel("Caret Status");
    statusPane.add(caretListenerLabel);

    JToolBar toolBar = new JToolBar();
    toolBar.add(new JButton("Btn1"));
    toolBar.add(new JButton("Btn2"));
    toolBar.add(new JButton("Btn3"));
    toolBar.add(new JButton("Btn4"));

    getContentPane().add(toolBar, BorderLayout.PAGE_START);
    getContentPane().add(splitPane, BorderLayout.CENTER);
    getContentPane().add(statusPane, BorderLayout.PAGE_END);

    JMenu editMenu = new JMenu("test");
    JMenu styleMenu = new JMenu("test");
    JMenuBar mb = new JMenuBar();
    mb.add(editMenu);
    mb.add(styleMenu);
    setJMenuBar(mb);

}

From source file:net.sf.firemox.ui.wizard.AboutMdb.java

/**
 * Creates a new instance of AboutMdb <br>
 * /* w  w w  .ja v a2s  .c om*/
 * @param parent
 */
public AboutMdb(JFrame parent) {
    super(LanguageManager.getString("about.tbs"),
            "<html><b>" + LanguageManager.getString("tbsname") + ": </b>" + MdbLoader.getTbsFullName()
                    + "<br><b>" + LanguageManager.getString("author") + ": </b>" + MdbLoader.getAuthor()
                    + "<br><b>" + LanguageManager.getString("info") + ": </b>" + MdbLoader.getMoreInfo()
                    + "<br><b>" + LanguageManager.getString("version") + ": </b>" + MdbLoader.getVersion(),
            "mp64.gif", LanguageManager.getString("close"), 420, 320);
    JTextArea disclaimer = new JTextArea();
    disclaimer.setEditable(false);
    disclaimer.setLineWrap(true);
    disclaimer.setWrapStyleWord(true);
    disclaimer.setAutoscrolls(true);
    // Then try and read it locally
    final InputStream inGPL = MToolKit.getResourceAsStream(MToolKit.mdbFile);
    if (inGPL != null) {
        disclaimer.setText(MdbLoader.getDisclaimer().replaceAll("\t", "").replaceAll("\n", ""));
        IOUtils.closeQuietly(inGPL);
    }
    JScrollPane disclaimerSPanel = new JScrollPane();
    disclaimerSPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    MToolKit.addOverlay(disclaimerSPanel);
    disclaimerSPanel.setViewportView(disclaimer);
    gameParamPanel.add(disclaimerSPanel);
    setLocation((getToolkit().getScreenSize().width - 420) / 2,
            (getToolkit().getScreenSize().height - 320) / 2);
}

From source file:net.sf.firemox.deckbuilder.DeckRules.java

/**
 * Create a new instance of DeckRules/*from  w ww  .jav a  2 s . c om*/
 * 
 * @param parent
 */
public DeckRules(JFrame parent) {
    super(LanguageManager.getString("jdeckrules", MdbLoader.getTbsFullName()),
            LanguageManager.getString("jdeckrules.tooltip", MdbLoader.getTbsFullName()), "wiz_library_wiz.png",
            LanguageManager.getString("close"), 490, 300);
    // ... Set initial text, scrolling, and border.
    final JTextArea textRules = new JTextArea();
    textRules.setEditable(false);
    textRules.setLineWrap(true);
    textRules.setWrapStyleWord(true);
    textRules.setAutoscrolls(true);
    textRules.setTabSize(2);
    textRules.setText("No defined rules");
    BufferedReader inGPL = null;
    try {
        inGPL = new BufferedReader(new FileReader(MToolKit.getTbsFile(
                "decks/DECK_CONSTRAINTS-" + LanguageManager.getLanguage().getLocale() + "-lang.info")));
        textRules.read(inGPL, "Deck constraints");
    } catch (IOException e) {
        // Ignore this error
    } finally {
        IOUtils.closeQuietly(inGPL);
    }

    final JScrollPane scrollingArea = new JScrollPane(textRules);
    gameParamPanel.add(scrollingArea);
    pack();
}