List of usage examples for javax.swing JTextArea setCaretPosition
@BeanProperty(bound = false, description = "the caret position") public void setCaretPosition(int position)
TextComponent
. From source file:org.p_vcd.ui.LicenseDialog.java
public LicenseDialog(String libName, String libHomepage, String licenseName, String licenseFilename) { setSize(680, 480);//from ww w.j av a2 s. c o m setTitle(libName); getContentPane().setLayout(new BorderLayout()); { JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.NORTH); panel.setLayout(new MigLayout("", "[grow,trailing][grow]", "[20px][][]")); { JLabel lblSoft = new JLabel(libName); lblSoft.setFont(new Font("Tahoma", Font.BOLD, 16)); panel.add(lblSoft, "center,cell 0 0 2 1"); } { JLabel lblHomePage = new JLabel("Home page:"); lblHomePage.setFont(new Font("Tahoma", Font.BOLD, 14)); panel.add(lblHomePage, "cell 0 1"); } { JLabel lblHome = SwingUtil.createLink(libHomepage, libHomepage); lblHome.setFont(new Font("Tahoma", Font.PLAIN, 14)); panel.add(lblHome, "cell 1 1"); } { JLabel lblNewLabel = new JLabel("License:"); lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14)); panel.add(lblNewLabel, "cell 0 2"); } { JLabel lblLicense = new JLabel(licenseName); lblLicense.setFont(new Font("Tahoma", Font.PLAIN, 14)); panel.add(lblLicense, "cell 1 2"); } } { JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.CENTER); panel.setLayout(new FlowLayout()); panel.setBorder(new EmptyBorder(5, 5, 5, 5)); JScrollPane scrollPane = new JScrollPane(); scrollPane.setPreferredSize(new Dimension(600, 300)); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); panel.add(scrollPane); { JTextArea txtLicense = new JTextArea(); txtLicense.setEditable(false); txtLicense.setFont(new Font("Monospaced", Font.PLAIN, 11)); txtLicense.setWrapStyleWord(true); txtLicense.setLineWrap(true); try { InputStream is = Thread.currentThread().getContextClassLoader() .getResourceAsStream("org/p_vcd/licenses/" + licenseFilename); String text = IOUtils.toString(is, "UTF-8"); IOUtils.closeQuietly(is); txtLicense.setText(text); txtLicense.setCaretPosition(0); } catch (Exception e) { e.printStackTrace(); } scrollPane.setViewportView(txtLicense); } } { JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.SOUTH); panel.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { LicenseDialog.this.dispose(); } }); okButton.setActionCommand("OK"); panel.add(okButton); getRootPane().setDefaultButton(okButton); } }
From source file:org.terentich.pram.GUIPRAM.java
private void showFileContent(File... files) { for (File file : files) { JPanel filePanel = new JPanel(new BorderLayout()); JTextArea textbox = new JTextArea(); filePanel.add(new JScrollPane(textbox)); tabPane.add(file.getName(), filePanel); tabPane.setSelectedComponent(filePanel); try {//www . j a va 2s. c o m @SuppressWarnings("unchecked") List<String> fileContent = FileUtils.readLines(file, CharEncoding.UTF_8); for (String line : fileContent) { textbox.append(line + "\n"); } textbox.setCaretPosition(0); } catch (IOException e) { e.printStackTrace(); } } }
From source file:pcgen.gui2.dialog.AboutDialog.java
/** * Build up a scrollable list of monkeys, given the monkey names. * @param monkeys The names of the monkeys * @return A JScrollPane to display the monkeys. */// w w w. ja v a 2s.c om private JScrollPane buildMonkeyList(String monkeys) { JTextArea textArea = new JTextArea(); JScrollPane scroller = new JScrollPane(); textArea.setWrapStyleWord(true); textArea.setLineWrap(true); textArea.setEditable(false); textArea.setText(monkeys); scroller.setViewportView(textArea); textArea.setCaretPosition(0); return scroller; }
From source file:pl.otros.logview.exceptionshandler.ShowErrorDialogExceptionHandler.java
@Override protected void uncaughtExceptionInSwingEDT(Thread thread, Throwable throwable) { String stackTraceAsString = Throwables.getStackTraceAsString(throwable); if (caughtStackTraces.contains(stackTraceAsString)) { LOGGER.info("Not sending the same error report twice"); return;/*from w w w .j ava2s . c om*/ } caughtStackTraces.add(stackTraceAsString); JPanel message = new JPanel(new BorderLayout()); message.add(new JLabel("Error in thread " + thread.getName()), BorderLayout.NORTH); String stackTrace = getStackTrace(throwable); JTextArea textArea = new JTextArea(10, 70); textArea.setText(stackTrace); textArea.setCaretPosition(0); message.add(new JScrollPane(textArea)); JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE); Map<String, String> errorReportData = generateReportData(thread, throwable, otrosApplication); JComponent jComponent = createDialogView(); String[] options = { "Send", "Do not send" }; int sendReport = JOptionPane.showOptionDialog(otrosApplication.getApplicationJFrame(), jComponent, "Send error report confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, Icons.MEGAPHONE_24, options, options[0]); errorReportData.put("USER:email", emailTextField.getText()); errorReportData.put("USER:comment", commentTextArea.getText()); if (sendReport == JOptionPane.YES_OPTION) { DataConfiguration c = otrosApplication.getConfiguration(); c.setProperty(ConfKeys.HTTP_PROXY_USE, checkBoxUseProxy.isSelected()); c.setProperty(ConfKeys.HTTP_PROXY_HOST, proxyTf.getText()); c.setProperty(ConfKeys.HTTP_PROXY_PORT, proxyPortModel.getNumber().intValue()); c.setProperty(ConfKeys.HTTP_PROXY_USER, proxyUser.getText()); sendReportInNewBackground(errorReportData); } else { LOGGER.info("Not sending error report"); } logErrorReport(errorReportData); }
From source file:qic.ui.AboutPanel.java
public AboutPanel() { BoxLayout boxLayout = new BoxLayout(this, BoxLayout.PAGE_AXIS); setLayout(boxLayout);/*from w w w . j ava 2 s . c o m*/ JLabel aboutLbl = new JLabel("<html>" + "<p>Durian Copyright (C) 2015 thirdy</p>" + "<p>This program is free software: you can redistribute it and/or modify</p>" + "<p>it under the terms of the GNU General Public License as published by</p>" + "<p>the Free Software Foundation, either version 3 of the License, or</p>" + "<p>(at your option) any later version.</p>" + "<p>This program comes with ABSOLUTELY NO WARRANTY.</p>" + "<p>A copy of the GNU General Public License can be found at https://github.com/thirdy/durian/blob/master/LICENSE</p>" + "<br/>" + "<br/>" + "<p>Thank you for using Durian. Durian is a fan-made software and is not affiliated with Grinding Gear Games in any way.</p>" + "<p>This software is 100% free and open source.</p>" + "<p>Durian is a fan-made software and is not affiliated with Grinding Gear Games in any way.</p>" + "<br/>" + "<br/>" + "<p>IGN: ManicCompression</p>" + "<p>Reddit: /u/ProFalseIdol</p>" + "</html>"); String websiteUrl = "http://thirdy.github.io/durian/"; JButton website = new JButtonLink("Website: " + websiteUrl, websiteUrl); String forumUrl = "https://www.pathofexile.com/forum/view-thread/1507190"; JButton forum = new JButtonLink("Forum Thread: " + forumUrl, forumUrl); String helpUrl = "http://thirdy.github.io/durian/help/help.htm"; JButton help = new JButtonLink("Search Term Helper: " + helpUrl, helpUrl); add(Box.createRigidArea(new Dimension(5, 10))); add(aboutLbl); add(Box.createRigidArea(new Dimension(5, 10))); add(website); add(Box.createRigidArea(new Dimension(5, 10))); add(forum); add(Box.createRigidArea(new Dimension(5, 10))); add(help); JPanel helpPanel = new JPanel(new BorderLayout()); helpPanel.setBorder(BorderFactory.createTitledBorder("Help")); JTextArea textArea = new JTextArea(); textArea.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12)); try { InputStream input = this.getClass().getResource("/help.txt").openStream(); String str = IOUtils.toString(input); textArea.setText(str); textArea.setCaretPosition(0); input.close(); } catch (Exception e) { logger.error("Error while reading help file", e); } helpPanel.add(new JScrollPane(textArea), BorderLayout.CENTER); add(Box.createRigidArea(new Dimension(5, 10))); add(helpPanel); }
From source file:utybo.branchingstorytree.swing.visuals.AboutDialog.java
@SuppressWarnings("unchecked") public AboutDialog(OpenBSTGUI parent) { super(parent); setTitle(Lang.get("about.title")); setModalityType(ModalityType.APPLICATION_MODAL); JPanel banner = new JPanel(new FlowLayout(FlowLayout.CENTER)); banner.setBackground(OpenBSTGUI.OPENBST_BLUE); JLabel lblOpenbst = new JLabel(new ImageIcon(Icons.getImage("FullLogoWhite", 48))); lblOpenbst.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); banner.add(lblOpenbst, "flowx,cell 0 0,alignx center"); getContentPane().add(banner, BorderLayout.NORTH); JPanel pan = new JPanel(); pan.setLayout(new MigLayout("insets 10, gap 10px", "[grow]", "[][][grow]")); getContentPane().add(pan, BorderLayout.CENTER); JLabel lblWebsite = new JLabel("https://utybo.github.io/BST/"); Font f = lblWebsite.getFont(); @SuppressWarnings("rawtypes") Map attrs = f.getAttributes(); attrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); lblWebsite.setFont(f.deriveFont(attrs)); lblWebsite.setForeground(OpenBSTGUI.OPENBST_BLUE); lblWebsite.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); lblWebsite.addMouseListener(new MouseAdapter() { @Override/*w w w . j a va2 s . c om*/ public void mouseClicked(MouseEvent e) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URL("https://utybo.github.io/BST/").toURI()); } catch (IOException | URISyntaxException e1) { OpenBST.LOG.warn("Exception when trying to open website", e1); } } } }); pan.add(lblWebsite, "cell 0 0,alignx center"); JLabel lblVersion = new JLabel(Lang.get("about.version").replace("$v", OpenBST.VERSION)); pan.add(lblVersion, "flowy,cell 0 1"); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBorder(new LineBorder(pan.getBackground().darker(), 1, false)); pan.add(scrollPane, "cell 0 2,grow"); JTextArea textArea = new JTextArea(); textArea.setMargin(new Insets(5, 5, 5, 5)); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setFont(new Font(textArea.getFont().getFontName(), Font.PLAIN, (int) (Icons.getScale() * 11))); try (InputStream in = getClass().getResourceAsStream("/utybo/branchingstorytree/swing/about.txt");) { textArea.setText(IOUtils.toString(in, StandardCharsets.UTF_8)); } catch (IOException ex) { OpenBST.LOG.warn("Loading about information failed", ex); } textArea.setEditable(false); textArea.setCaretPosition(0); scrollPane.setViewportView(textArea); JLabel lblTranslatedBy = new JLabel(Lang.get("author")); pan.add(lblTranslatedBy, "cell 0 1"); setSize((int) (Icons.getScale() * 450), (int) (Icons.getScale() * 400)); setLocationRelativeTo(parent); }