List of usage examples for javax.swing JTextArea setBackground
@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.") public void setBackground(Color bg)
From source file:au.org.ala.delta.ui.MessageDialogHelper.java
/** * Creates a text area that looks like a JLabel that has a preferredSize calculated to fit * all of the supplied text wrapped at the supplied column. * @param text the text to display in the JTextArea. * @param numColumns the column number to wrap text at. * @return a new JTextArea configured for the supplied text. *///w ww .j a v a2s .c o m private static JTextArea createMessageDisplay(String text, int numColumns) { JTextArea textArea = new JTextArea(); textArea.setEditable(false); textArea.setBackground(UIManager.getColor("Label.background")); textArea.setFont(UIManager.getFont("Label.font")); textArea.setWrapStyleWord(true); textArea.setLineWrap(true); textArea.setColumns(numColumns); String wrapped = WordUtils.wrap(text, numColumns); textArea.setRows(wrapped.split("\n").length - 1); textArea.setText(text); // Need to set a preferred size so that under OpenJDK-6 on Linux the JOptionPanes get reasonable bounds textArea.setPreferredSize(new Dimension(0, 0)); return textArea; }
From source file:Main.java
public static JScrollPane createScrollPane(JTextArea textArea, Font font, Color bgColor) { JScrollPane scrollPane = new JScrollPane(textArea); textArea.setLineWrap(true);/* w w w . ja v a 2 s . c o m*/ textArea.setWrapStyleWord(true); if (null != font) { textArea.setFont(font); } textArea.setOpaque(true); if (bgColor != null) { textArea.setBackground(bgColor); } return scrollPane; }
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;/* w ww. j a v a 2 s .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 ww. j ava 2 s . c o m * {@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:Main.java
public Console() { JTextArea textArea = new JTextArea(24, 80); textArea.setBackground(Color.BLACK); textArea.setForeground(Color.LIGHT_GRAY); textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); System.setOut(new PrintStream(new OutputStream() { @Override/*from w ww.j av a 2 s. c o m*/ public void write(int b) throws IOException { textArea.append(String.valueOf((char) b)); } })); frame.add(textArea); }
From source file:agentlogfileanalyzer.histogram.AbstractHistogram.java
/** * Creates a panel for error messages. The error message is given as * parameter./* ww w.j av a2 s.com*/ * * @param _text * the error message * @return a panel for error messages */ private JPanel createErrorPanel(String _text) { JPanel jPanelChart = new JPanel(); // ...display error notice instead of chart. JTextArea jTextAreaAnzeige = new JTextArea(_text); jTextAreaAnzeige.setVisible(true); jTextAreaAnzeige.setBackground(new Color(238, 238, 238)); jPanelChart.add(jTextAreaAnzeige); jPanelChart.setVisible(true); return jPanelChart; }
From source file:com.sshtools.common.ui.SshToolsApplicationPanel.java
/** * Show an error message with toggable detail * * @param parent/* w w w. java 2s . c om*/ * @param mesg * @param title * @param exception */ public static void showErrorMessage(Component parent, String mesg, String title, Throwable exception) { boolean details = false; while (true) { String[] opts = new String[] { details ? "Hide Details" : "Details", "Ok" }; StringBuffer buf = new StringBuffer(); if (mesg != null) { buf.append(mesg); } appendException(exception, 0, buf, details); //MultilineLabel message = new MultilineLabel(buf.toString()); javax.swing.JTextArea message = new javax.swing.JTextArea(buf.toString()); message.setEditable(false); message.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4)); javax.swing.JLabel jl = new javax.swing.JLabel(); message.setFont(jl.getFont()); message.setBackground(jl.getBackground()); int opt = JOptionPane.showOptionDialog(parent, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE, null, opts, opts[1]); if (opt == 0) { details = !details; } else { break; } } }
From source file:SysConfig.java
public SysConfig() { super("JTabbedPane & BoxLayout Demonstration"); setSize(500, 300);// w w w . j a va 2 s. co m setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel configPane = new JPanel(); configPane.setLayout(new BoxLayout(configPane, BoxLayout.Y_AXIS)); JTextArea question = new JTextArea("Which of the following options\n" + "do you have installed?"); // Ok, now configure the textarea to show up properly inside the box. // This is part of the "high art" of Swing... question.setEditable(false); question.setMaximumSize(new Dimension(300, 50)); question.setAlignmentX(0.0f); question.setBackground(configPane.getBackground()); JCheckBox audioCB = new JCheckBox("Sound Card", true); JCheckBox nicCB = new JCheckBox("Ethernet Card", true); JCheckBox tvCB = new JCheckBox("Video Out", false); configPane.add(Box.createVerticalGlue()); configPane.add(question); configPane.add(audioCB); configPane.add(nicCB); configPane.add(tvCB); configPane.add(Box.createVerticalGlue()); JLabel audioPane = new JLabel("Audio stuff"); JLabel nicPane = new JLabel("Networking stuff"); JLabel tvPane = new JLabel("Video stuff"); JLabel helpPane = new JLabel("Help information"); audioCB.addItemListener(new TabManager(audioPane)); nicCB.addItemListener(new TabManager(nicPane)); tvCB.addItemListener(new TabManager(tvPane)); config.addTab("System", null, configPane, "Choose Installed Options"); config.addTab("Audio", null, audioPane, "Audio system configuration"); config.addTab("Networking", null, nicPane, "Networking configuration"); config.addTab("Video", null, tvPane, "Video system configuration"); config.addTab("Help", null, helpPane, "How Do I..."); getContentPane().add(config, BorderLayout.CENTER); }
From source file:com.mindcognition.mindraider.ui.swing.concept.annotation.renderer.AbstractTextAnnotationRenderer.java
private void configureEditor(JTextArea annotationTextArea) { // TODO use colors from the configuration annotationTextArea.setForeground(Color.WHITE); annotationTextArea.setBackground(Color.BLACK); annotationTextArea.setCaretColor(Color.RED); annotationTextArea.setSelectionColor(Color.YELLOW); annotationTextArea.setLineWrap(true); annotationTextArea.setWrapStyleWord(true); annotationTextArea.setFont(TEXTAREA_FONT); ;//from www .j a v a2s .c om // undo and redo undoManager = new UndoManager(); annotationTextArea.getDocument().addUndoableEditListener(new EditorUndoListner(undoManager, toolbar)); }
From source file:ecosim.gui.SummaryPane.java
/** * Private method to build the text pane. * * @return A JLayeredPane containing the text pane. *//*from ww w . j a v a2 s.c o m*/ private JLayeredPane makeTextPane() { final String ls = System.getProperty("line.separator"); final String fmt = "Outgroup: %s" + ls + "Number: %,d" + ls + "Length: %,d" + ls + "Diversity: %.2f" + ls; final JLayeredPane pane = new JLayeredPane(); final JTextArea summaryTextArea = new JTextArea(String.format(fmt, summary.getOutgroup(), summary.getNu(), summary.getLength(), summary.getDiversity())); summaryTextArea.setBackground(getBackground()); pane.setBorder(BorderFactory.createTitledBorder("Sequences")); pane.setLayout(new FlowLayout(0)); pane.add(summaryTextArea); // Watch for changes to the Summary object. summary.addObserver(new Observer() { public void update(Observable o, Object obj) { Summary s = (Summary) obj; ParameterEstimate estimate = s.getEstimate(); summaryTextArea .setText(String.format(fmt, s.getOutgroup(), s.getNu(), s.getLength(), s.getDiversity())); pane.repaint(); } }); return pane; }