List of usage examples for javax.swing JTextArea setText
@BeanProperty(bound = false, description = "the text of this component") public void setText(String t)
TextComponent
to the specified text. From source file:Main.java
public Main() { setSize(300, 300);//w ww .ja v a2s . co m setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextArea textArea = new JTextArea(); textArea.setText("Click Me!"); textArea.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.NOBUTTON) { textArea.setText("No button clicked..."); } else if (e.getButton() == MouseEvent.BUTTON1) { textArea.setText("Button 1 clicked..."); } else if (e.getButton() == MouseEvent.BUTTON2) { textArea.setText("Button 2 clicked..."); } else if (e.getButton() == MouseEvent.BUTTON3) { textArea.setText("Button 3 clicked..."); } System.out.println("Number of click: " + e.getClickCount()); System.out.println("Click position (X, Y): " + e.getX() + ", " + e.getY()); } }); getContentPane().add(textArea); }
From source file:edu.ku.brc.specify.ui.AppBase.java
/** * Creates a ScrollPane with the text from the log file. * @param logFile the file/* ww w.ja v a2 s . c o m*/ * @param doError indicates it should display the error log * @return the ScrollPane. */ protected static JScrollPane getLogFilePanel(final File logFile, final boolean doError) { JTextArea textArea = new JTextArea(); if (logFile.exists()) { try { textArea.setText(FileUtils.readFileToString(logFile)); } catch (Exception ex) { } // no catch on purpose } else { textArea.setText( doError ? getResourceString("Specify.LOG_NO_ERRORS") : getResourceString("Specify.LOG_EMPTY")); //$NON-NLS-1$ //$NON-NLS-2$ } textArea.setEditable(false); return new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); }
From source file:BoxLayoutPane.java
public BoxLayoutPane() { // Use a BorderLayout layout manager to arrange various Box components this.setLayout(new BorderLayout()); // Give the entire panel a margin by adding an empty border // We could also do this by overriding getInsets() this.setBorder(new EmptyBorder(10, 10, 10, 10)); // Add a plain row of buttons along the top of the pane Box row = Box.createHorizontalBox(); for (int i = 0; i < 4; i++) { JButton b = new JButton("B" + i); b.setFont(new Font("serif", Font.BOLD, 12 + i * 2)); row.add(b);/* w w w. j a v a 2 s . com*/ } this.add(row, BorderLayout.NORTH); // Add a plain column of buttons along the right edge // Use BoxLayout with a different kind of Swing container // Give the column a border: can't do this with the Box class JPanel col = new JPanel(); col.setLayout(new BoxLayout(col, BoxLayout.Y_AXIS)); col.setBorder(new TitledBorder(new EtchedBorder(), "Column")); for (int i = 0; i < 4; i++) { JButton b = new JButton("Button " + i); b.setFont(new Font("sanserif", Font.BOLD, 10 + i * 2)); col.add(b); } this.add(col, BorderLayout.EAST); // Add column to right of panel // Add a button box along the bottom of the panel. // Use "Glue" to space the buttons evenly Box buttonbox = Box.createHorizontalBox(); buttonbox.add(Box.createHorizontalGlue()); // stretchy space buttonbox.add(new JButton("Okay")); buttonbox.add(Box.createHorizontalGlue()); // stretchy space buttonbox.add(new JButton("Cancel")); buttonbox.add(Box.createHorizontalGlue()); // stretchy space buttonbox.add(new JButton("Help")); buttonbox.add(Box.createHorizontalGlue()); // stretchy space this.add(buttonbox, BorderLayout.SOUTH); // Create a component to display in the center of the panel JTextArea textarea = new JTextArea(); textarea.setText("This component has 12-pixel margins on left and top" + " and has 72-pixel margins on right and bottom."); textarea.setLineWrap(true); textarea.setWrapStyleWord(true); // Use Box objects to give the JTextArea an unusual spacing // First, create a column with 3 kids. The first and last kids // are rigid spaces. The middle kid is the text area Box fixedcol = Box.createVerticalBox(); fixedcol.add(Box.createVerticalStrut(12)); // 12 rigid pixels fixedcol.add(textarea); // Component fills in the rest fixedcol.add(Box.createVerticalStrut(72)); // 72 rigid pixels // Now create a row. Give it rigid spaces on the left and right, // and put the column from above in the middle. Box fixedrow = Box.createHorizontalBox(); fixedrow.add(Box.createHorizontalStrut(12)); fixedrow.add(fixedcol); fixedrow.add(Box.createHorizontalStrut(72)); // Now add the JTextArea in the column in the row to the panel this.add(fixedrow, BorderLayout.CENTER); }
From source file:com.ansorgit.plugins.bash.editor.inspections.inspections.FixShebangInspection.java
@Override public JComponent createOptionsPanel() { FixShebangSettings settings = new FixShebangSettings(); JTextArea textArea = settings.getValidCommandsTextArea(); textArea.setText(Joiner.on('\n').join(validShebangCommands)); textArea.getDocument().addDocumentListener(new DocumentListener() { @Override//from ww w . j av a 2 s.com public void insertUpdate(DocumentEvent documentEvent) { updateShebangLines(documentEvent); } @Override public void removeUpdate(DocumentEvent documentEvent) { updateShebangLines(documentEvent); } @Override public void changedUpdate(DocumentEvent documentEvent) { updateShebangLines(documentEvent); } }); return settings.getSettingsPanel(); }
From source file:DropDemo.java
private JPanel createArea() { String text = "Drag from or drop into this area.\nThe default action is MOVE;\nhold the Control key to COPY."; JTextArea area = new JTextArea(); area.setText(text); area.setDragEnabled(true);/*from w ww .j a va 2 s. c om*/ JScrollPane scrollPane = new JScrollPane(area); scrollPane.setPreferredSize(new Dimension(400, 100)); JPanel panel = new JPanel(new BorderLayout()); panel.add(scrollPane, BorderLayout.CENTER); panel.setBorder(BorderFactory.createTitledBorder("Text Area")); return panel; }
From source file:net.sf.firemox.deckbuilder.DeckRules.java
/** * Create a new instance of DeckRules//from ww w . j a va 2s . 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(); }
From source file:hermes.renderers.fix.FIXMessageRenderer.java
@Override public JComponent render(JScrollPane parent, Message m) { try {//from ww w . ja v a 2s . c o m JComponent rval = null; if (getPanelMap().containsKey(m)) { rval = (JComponent) getPanelMap().get(m); } else { if (m instanceof TextMessage) { rval = handleTextMessage((TextMessage) m); } else if (m instanceof javax.jms.ObjectMessage) { rval = handleObjectMessage((ObjectMessage) m); } else if (m instanceof javax.jms.MapMessage) { rval = handleMapMessage((MapMessage) m); } else if (m instanceof BytesMessage) { rval = handleBytesMessage((BytesMessage) m); } else if (m instanceof StreamMessage) { rval = handleStreamMessage((StreamMessage) m); } if (rval != null) { getPanelMap().put(m, rval); } } return rval; } catch (Throwable ex) { final JTextArea textArea = new JTextArea(); textArea.setEditable(false); textArea.setText("Unable to display message: " + ex.getMessage()); log.error(ex.getMessage(), ex); return textArea; } }
From source file:ExtendedDnDDemo.java
private JPanel createArea() { String text = "This is the text that I want to show."; JTextArea area = new JTextArea(); area.setText(text); area.setDragEnabled(true);//ww w .j a v a 2 s . co m JScrollPane scrollPane = new JScrollPane(area); scrollPane.setPreferredSize(new Dimension(400, 100)); JPanel panel = new JPanel(new BorderLayout()); panel.add(scrollPane, BorderLayout.CENTER); panel.setBorder(BorderFactory.createTitledBorder("Text Area")); return panel; }
From source file:CubaHSQLDBServer.java
private void setTextPreserveSize(JTextArea target, String text) { Dimension size = target.getPreferredSize(); target.setText(text); target.setPreferredSize(size);//ww w . j ava2 s.co m }
From source file:net.sf.firemox.ui.wizard.AboutMdb.java
/** * Creates a new instance of AboutMdb <br> * //from ww w . j a v a 2 s. 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); }