List of usage examples for javax.swing JTextArea setLineWrap
@BeanProperty(preferred = true, description = "should lines be wrapped") public void setLineWrap(boolean wrap)
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JTextArea ta = new JTextArea(5, 32); ta.setText("That's one small step for man...\nOne giant leap for mankind."); ta.setLineWrap(true); ta.setWrapStyleWord(true);/* ww w. java2s . c o m*/ f.getContentPane().add(ta); f.setSize(100, 100); f.setVisible(true); ((AbstractDocument) ta.getDocument()).dump(System.out); }
From source file:LineHighlightPainter.java
public static void main(String args[]) { // extend DefaultCaret as an anonymous inner class Caret lineHighlightPainterCaret = new DefaultCaret() { private Highlighter.HighlightPainter lhp = new LineHighlightPainter(); // override getSelectionPainter to return the LineHighlightPainter protected Highlighter.HighlightPainter getSelectionPainter() { return lhp; }// ww w .ja va2 s.c o m }; JFrame frame = new JFrame("LineHighlightPainter demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea area = new JTextArea(9, 45); area.setCaret(lineHighlightPainterCaret); area.setLineWrap(true); area.setWrapStyleWord(true); area.setText("This is the story\nof the hare who\nlost his spectacles."); frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:ScrollPaneWatermark.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); JTextArea ta = new JTextArea(); for (int i = 0; i < 1000; i++) { ta.append(Integer.toString(i) + " "); }//from www . jav a2 s. c om ta.setLineWrap(true); ta.setWrapStyleWord(true); // ta.setOpaque(false); ScrollPaneWatermark watermark = new ScrollPaneWatermark(); watermark.setBackgroundTexture(new File("background.jpg").toURL()); watermark.setForegroundBadge(new File("foreground.png").toURL()); watermark.setView(ta); JScrollPane scroll = new JScrollPane(); scroll.setViewport(watermark); frame.getContentPane().add(scroll); frame.pack(); frame.setSize(600, 600); frame.setVisible(true); }
From source file:FlowLayoutTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("FlowLayout Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String text = "A JTextArea object represents" + "a multiline area for displaying text." + "You can change the number of lines" + "that can be displayed at a time."; JTextArea textArea1 = new JTextArea(text, 5, 10); textArea1.setPreferredSize(new Dimension(100, 100)); JTextArea textArea2 = new JTextArea(text, 5, 10); textArea2.setPreferredSize(new Dimension(100, 100)); JScrollPane scrollPane = new JScrollPane(textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); textArea1.setLineWrap(true); textArea2.setLineWrap(true);/*from w w w. j a v a 2 s. c om*/ frame.add(textArea1); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String text = "A JTextArea object represents a multiline area for displaying text. " + "You can change the number of lines that can be displayed at a time, " + "as well as the number of columns. You can wrap lines and words too. " + "You can also put your JTextArea in a JScrollPane to make it scrollable."; JTextArea textAreal = new JTextArea(text, 5, 10); textAreal.setPreferredSize(new Dimension(100, 100)); JTextArea textArea2 = new JTextArea(text, 5, 10); textArea2.setPreferredSize(new Dimension(100, 100)); JScrollPane scrollPane = new JScrollPane(textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); textAreal.setLineWrap(true); textArea2.setLineWrap(true);/*from www . jav a 2s .c om*/ frame.add(textAreal); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }
From source file:com.edduarte.protbox.Protbox.java
public static void main(String... args) { // activate debug / verbose mode if (args.length != 0) { List<String> argsList = Arrays.asList(args); if (argsList.contains("-v")) { Constants.verbose = true;/* w w w .j a va2s .co m*/ } } // use System's look and feel try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { // If the System's look and feel is not obtainable, continue execution with JRE look and feel } // check this is a single instance try { new ServerSocket(1882); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Another instance of Protbox is already running.\n" + "Please close the other instance first.", "Protbox already running", JOptionPane.ERROR_MESSAGE); System.exit(1); } // check if System Tray is supported by this operative system if (!SystemTray.isSupported()) { JOptionPane.showMessageDialog(null, "Your operative system does not support system tray functionality.\n" + "Please try running Protbox on another operative system.", "System tray not supported", JOptionPane.ERROR_MESSAGE); System.exit(1); } // add PKCS11 providers FileFilter fileFilter = new AndFileFilter(new WildcardFileFilter(Lists.newArrayList("*.config")), HiddenFileFilter.VISIBLE); File[] providersConfigFiles = new File(Constants.PROVIDERS_DIR).listFiles(fileFilter); if (providersConfigFiles != null) { for (File f : providersConfigFiles) { try { List<String> lines = FileUtils.readLines(f); String aliasLine = lines.stream().filter(line -> line.contains("alias")).findFirst().get(); lines.remove(aliasLine); String alias = aliasLine.split("=")[1].trim(); StringBuilder sb = new StringBuilder(); for (String s : lines) { sb.append(s); sb.append("\n"); } Provider p = new SunPKCS11(new ReaderInputStream(new StringReader(sb.toString()))); Security.addProvider(p); pkcs11Providers.put(p.getName(), alias); } catch (IOException | ProviderException ex) { if (ex.getMessage().equals("Initialization failed")) { ex.printStackTrace(); String s = "The following error occurred:\n" + ex.getCause().getMessage() + "\n\nIn addition, make sure you have " + "an available smart card reader connected before opening the application."; JTextArea textArea = new JTextArea(s); textArea.setColumns(60); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setSize(textArea.getPreferredSize().width, 1); JOptionPane.showMessageDialog(null, textArea, "Error loading PKCS11 provider", JOptionPane.ERROR_MESSAGE); System.exit(1); } else { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Error while setting up PKCS11 provider from configuration file " + f.getName() + ".\n" + ex.getMessage(), "Error loading PKCS11 provider", JOptionPane.ERROR_MESSAGE); } } } } // adds a shutdown hook to save instantiated directories into files when the application is being closed Runtime.getRuntime().addShutdownHook(new Thread(Protbox::exit)); // get system tray and run tray applet tray = SystemTray.getSystemTray(); SwingUtilities.invokeLater(() -> { if (Constants.verbose) { logger.info("Starting application"); } //Start a new TrayApplet object trayApplet = TrayApplet.getInstance(); }); // prompts the user to choose which provider to use ProviderListWindow.showWindow(Protbox.pkcs11Providers.keySet(), providerName -> { // loads eID token eIDTokenLoadingWindow.showPrompt(providerName, (returnedUser, returnedCertificateData) -> { user = returnedUser; certificateData = returnedCertificateData; // gets a password to use on the saved registry files (for loading and saving) final AtomicReference<Consumer<SecretKey>> consumerHolder = new AtomicReference<>(null); consumerHolder.set(password -> { registriesPasswordKey = password; try { // if there are serialized files, load them if they can be decoded by this user's private key final List<SavedRegistry> serializedDirectories = new ArrayList<>(); if (Constants.verbose) { logger.info("Reading serialized registry files..."); } File[] registryFileList = new File(Constants.REGISTRIES_DIR).listFiles(); if (registryFileList != null) { for (File f : registryFileList) { if (f.isFile()) { byte[] data = FileUtils.readFileToByteArray(f); try { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, registriesPasswordKey); byte[] registryDecryptedData = cipher.doFinal(data); serializedDirectories.add(new SavedRegistry(f, registryDecryptedData)); } catch (GeneralSecurityException ex) { if (Constants.verbose) { logger.info("Inserted Password does not correspond to " + f.getName()); } } } } } // if there were no serialized directories, show NewDirectory window to configure the first folder if (serializedDirectories.isEmpty() || registryFileList == null) { if (Constants.verbose) { logger.info("No registry files were found: running app as first time!"); } NewRegistryWindow.start(true); } else { // there were serialized directories loadRegistry(serializedDirectories); trayApplet.repaint(); showTrayApplet(); } } catch (AWTException | IOException | GeneralSecurityException | ReflectiveOperationException | ProtboxException ex) { JOptionPane.showMessageDialog(null, "The inserted password was invalid! Please try another one!", "Invalid password!", JOptionPane.ERROR_MESSAGE); insertPassword(consumerHolder.get()); } }); insertPassword(consumerHolder.get()); }); }); }
From source file:Main.java
public static void showMessage(String title, String str) { JFrame info = new JFrame(title); JTextArea t = new JTextArea(str, 15, 40); t.setEditable(false);//from ww w .ja va2 s.c o m t.setLineWrap(true); t.setWrapStyleWord(true); JButton ok = new JButton("Close"); ok.addActionListener(windowCloserAction); info.getContentPane().setLayout(new BoxLayout(info.getContentPane(), BoxLayout.Y_AXIS)); info.getContentPane().add(new JScrollPane(t)); info.getContentPane().add(ok); ok.setAlignmentX(Component.CENTER_ALIGNMENT); info.pack(); //info.setResizable(false); centerFrame(info); //info.show(); info.setVisible(true); }
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 www .ja v a 2 s . c om 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
public static JScrollPane createScrollPane(JTextArea textArea, Font font, Color bgColor) { JScrollPane scrollPane = new JScrollPane(textArea); textArea.setLineWrap(true); textArea.setWrapStyleWord(true);/*from w w w . ja v a 2s.c o m*/ if (null != font) { textArea.setFont(font); } textArea.setOpaque(true); if (bgColor != null) { textArea.setBackground(bgColor); } return scrollPane; }
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./*from ww w.ja v a 2 s . c om*/ * @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); }