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:KeymapExample.java
public static void main(String[] args) { JTextArea area = new JTextArea(6, 32); Keymap parent = area.getKeymap(); Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent); KeyStroke u = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK); Action actionU = new UpWord(); newmap.addActionForKeyStroke(u, actionU); Action actionList[] = area.getActions(); Hashtable lookup = new Hashtable(); for (int j = 0; j < actionList.length; j += 1) lookup.put(actionList[j].getValue(Action.NAME), actionList[j]); KeyStroke L = KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK); Action actionL = (Action) lookup.get(DefaultEditorKit.selectLineAction); newmap.addActionForKeyStroke(L, actionL); KeyStroke W = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK); Action actionW = (Action) lookup.get(DefaultEditorKit.selectWordAction); newmap.addActionForKeyStroke(W, actionW); area.setKeymap(newmap);//from w ww .j a v a2 s .c o m JFrame f = new JFrame("KeymapExample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); area.setText("This is a test."); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void displayErrorMessage(JFrame frame, String errorMessage) { // create a JTextArea JTextArea textArea = new JTextArea(6, 25); textArea.setText(errorMessage); textArea.setEditable(false);// ww w . j av a 2 s. c o m // wrap a scrollpane around it JScrollPane scrollPane = new JScrollPane(textArea); // display them in a message dialog // TODO i don't know if this will work if this is null JOptionPane.showMessageDialog(frame, scrollPane); }
From source file:com.SCI.centraltoko.utility.UtilityTools.java
private static void convertToUpperCase(final JTextArea textArea) { textArea.setText(textArea.getText().toUpperCase()); }
From source file:eu.delving.sip.Application.java
private static void memoryNotConfigured() { String os = System.getProperty("os.name"); Runtime rt = Runtime.getRuntime(); int totalMemory = (int) (rt.totalMemory() / 1024 / 1024); StringBuilder out = new StringBuilder(); String JAR_NAME = "SIP-Creator-2014-XX-XX.jar"; if (os.startsWith("Windows")) { out.append(":: SIP-Creator Startup Batch file for Windows (more memory than ").append(totalMemory) .append("Mb)\n"); out.append("java -jar -Xms1024m -Xmx1024m ").append(JAR_NAME); } else if (os.startsWith("Mac")) { out.append("# SIP-Creator Startup Script for Mac OSX (more memory than ").append(totalMemory) .append("Mb)\n"); out.append("java -jar -Xms1024m -Xmx1024m ").append(JAR_NAME); } else {//from ww w. j ava 2 s . co m System.out.println("Unrecognized OS: " + os); } String script = out.toString(); final JDialog dialog = new JDialog(null, "Memory Not Configured Yet!", Dialog.ModalityType.APPLICATION_MODAL); JTextArea scriptArea = new JTextArea(3, 40); scriptArea.setText(script); scriptArea.setSelectionStart(0); scriptArea.setSelectionEnd(script.length()); JPanel scriptPanel = new JPanel(new BorderLayout()); scriptPanel.setBorder(BorderFactory.createTitledBorder("Script File")); scriptPanel.add(scriptArea, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); JButton ok = new JButton("OK, Continue anyway"); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); EventQueue.invokeLater(LAUNCH); } }); buttonPanel.add(ok); JPanel centralPanel = new JPanel(new GridLayout(0, 1)); centralPanel.setBorder(BorderFactory.createEmptyBorder(15, 25, 15, 25)); centralPanel.add( new JLabel("<html><b>The SIP-Creator started directly can have too little default memory allocated." + "<br>It should be started with the following script:</b>")); centralPanel.add(scriptPanel); centralPanel.add(new JLabel( "<html><b>Please copy the above text into a batch or script file and execute that instead.</b>")); dialog.getContentPane().add(centralPanel, BorderLayout.CENTER); dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH); dialog.pack(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - dialog.getWidth()) / 2); int y = (int) ((dimension.getHeight() - dialog.getHeight()) / 2); dialog.setLocation(x, y); dialog.setVisible(true); }
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. *///from w ww. j a v a 2 s . 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: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 2 s .c o m } 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:edu.ku.brc.specify.ui.db.AskForNumbersDlg.java
/** * @param list//from w w w .j a va 2s. c o m * @param ta */ protected static void buildNumberList(final List<String> list, final JTextArea ta) { StringBuilder sb = new StringBuilder(); if (list != null && list.size() > 0) { for (String num : list) { if (sb.length() > 0) sb.append(", "); sb.append(num); } } ta.setText(sb.toString()); }
From source file:kevin.gvmsgarch.App.java
public static void showErrorDialog(final Exception text) { try {//from ww w. java 2 s. co m SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JPanel panel = new JPanel(); JTextArea textArea = new JTextArea(); JScrollPane scroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroll.setMinimumSize(new Dimension(800, 240)); panel.add(scroll); panel.setMinimumSize(new Dimension(800, 240)); ByteArrayOutputStream baos; text.printStackTrace(new PrintStream(baos = new ByteArrayOutputStream())); textArea.setText(new String(baos.toByteArray())); JOptionPane.showConfirmDialog(null, panel, "Why did this happen?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); } }); } catch (Exception ex) { System.err.println("ermmm...?"); ex.printStackTrace(); } }
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 ww w . j a v a 2 s .com*/ 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 Main() { JTextArea area = new JTextArea(5, 20); area.setText("this is a test."); String charsToHighlight = "aeiouAEIOU"; Highlighter h = area.getHighlighter(); h.removeAllHighlights();//from ww w .j a v a 2s . c o m String text = area.getText().toUpperCase(); for (int i = 0; i < text.length(); i += 1) { char ch = text.charAt(i); if (charsToHighlight.indexOf(ch) >= 0) try { h.addHighlight(i, i + 1, DefaultHighlighter.DefaultPainter); } catch (Exception ble) { } } this.getContentPane().add(area); }