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:biomine.bmvis2.pipeline.sources.QueryGraphSource.java
@Override public BMGraph getBMGraph() throws GraphOperationException { try {/*from www .java 2s . co m*/ if (fetch == null) { fetch = new CrawlerFetch(query, neighborhood, database); } if (ret == null) { final JDialog dial = new JDialog((JFrame) null); dial.setTitle("BMVIS II - Query to database"); dial.setSize(400, 200); dial.setMinimumSize(new Dimension(400, 200)); dial.setResizable(false); final JTextArea text = new JTextArea(); text.setEditable(false); dial.add(text); text.setText("..."); class Z { Exception runExc = null; } final Z z = new Z(); Runnable fetchThread = new Runnable() { public void run() { try { long startTime = System.currentTimeMillis(); while (!fetch.isDone()) { fetch.update(); Thread.sleep(500); long time = System.currentTimeMillis(); long elapsed = time - startTime; if (elapsed > 30000) { throw new GraphOperationException("Timeout while querying " + query); } final String newText = fetch.getState() + ":\n" + fetch.getMessages(); SwingUtilities.invokeLater(new Runnable() { public void run() { text.setText(newText); } }); } SwingUtilities.invokeAndWait(new Runnable() { public void run() { dial.setVisible(false); } }); } catch (Exception e) { z.runExc = e; } } }; new Thread(fetchThread).start(); dial.setModalityType(ModalityType.APPLICATION_MODAL); dial.setVisible(true); ret = fetch.getBMGraph(); if (ret == null) throw new GraphOperationException(fetch.getMessages()); if (z.runExc != null) { if (z.runExc instanceof GraphOperationException) throw (GraphOperationException) z.runExc; else throw new GraphOperationException(z.runExc); } } } catch (IOException e) { throw new GraphOperationException(e); } updateInfo(); return ret; }
From source file:SplitPaneTest.java
public SplitPaneFrame() { setTitle("SplitPaneTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // set up components for planet names, images, descriptions final JList planetList = new JList(planets); final JLabel planetImage = new JLabel(); final JTextArea planetDescription = new JTextArea(); planetList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { Planet value = (Planet) planetList.getSelectedValue(); // update image and description planetImage.setIcon(value.getImage()); planetDescription.setText(value.getDescription()); }// w w w. j a v a 2 s . c om }); // set up split panes JSplitPane innerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, planetList, planetImage); innerPane.setContinuousLayout(true); innerPane.setOneTouchExpandable(true); JSplitPane outerPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, innerPane, planetDescription); add(outerPane, BorderLayout.CENTER); }
From source file:medsavant.uhn.cancer.UserCommentApp.java
private JPanel getCommentPanel(UserComment lc) { JTextArea commentText = new JTextArea(); commentText.setText(lc.getCommentText()); commentText.setEditable(false);/*from www.jav a 2 s .com*/ commentText.setLineWrap(true); commentText.setPreferredSize(new Dimension(COMMENTTEXT_PREFERRED_WIDTH, COMMENTTEXT_PREFERRED_HEIGHT)); JScrollPane jsp = new JScrollPane(commentText); JPanel outerCommentPanel = new JPanel(); outerCommentPanel.setLayout(new BoxLayout(outerCommentPanel, BoxLayout.X_AXIS)); outerCommentPanel.add(jsp); outerCommentPanel.add(Box.createHorizontalGlue()); return outerCommentPanel; }
From source file:fi.marketing.list.ui.DashboardUI.java
private void setTextAndType(javax.swing.JTextArea two, javax.swing.JTextArea three, fi.marketing.list.logic.Type tp) { MarketingList list = oper.createAMarketingList(nameNewMarketingList.getText(), tp); two.setText(oper.getWrittenCount() + " rows were saved to the " + nameNewMarketingList.getText() + ".txt file."); three.setText(list.printString());/*from w ww .j av a2 s. c o m*/ }
From source file:com.mindcognition.mindraider.ui.swing.concept.annotation.renderer.RichTextAnnotationRenderer.java
private void insertStringToAnnotation(String stringToInsert) { JTextArea editor = richTextAnnotationRenderer.editor; try {/*from w w w . jav a 2s. c o m*/ final int caretPosition = editor.getCaretPosition(); // link & htmlize String linked = editor.getDocument().getText(0, caretPosition) + stringToInsert + editor.getDocument().getText(caretPosition, editor.getDocument().getLength() - caretPosition); linked = linked.trim(); // set to UI again editor.setText(linked); editor.setCaretPosition(caretPosition); } catch (Exception e) { e.printStackTrace(); } }
From source file:SwingDnDTest.java
public SwingDnDFrame() { setTitle("SwingDnDTest"); JTabbedPane tabbedPane = new JTabbedPane(); JList list = SampleComponents.list(); tabbedPane.addTab("List", list); JTable table = SampleComponents.table(); tabbedPane.addTab("Table", table); JTree tree = SampleComponents.tree(); tabbedPane.addTab("Tree", tree); JFileChooser fileChooser = new JFileChooser(); tabbedPane.addTab("File Chooser", fileChooser); JColorChooser colorChooser = new JColorChooser(); tabbedPane.addTab("Color Chooser", colorChooser); final JTextArea textArea = new JTextArea(4, 40); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Drag text here")); JTextField textField = new JTextField("Drag color here"); textField.setTransferHandler(new TransferHandler("background")); tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { textArea.setText(""); }//from ww w .j a v a 2 s . c om }); tree.setDragEnabled(true); table.setDragEnabled(true); list.setDragEnabled(true); fileChooser.setDragEnabled(true); colorChooser.setDragEnabled(true); textField.setDragEnabled(true); add(tabbedPane, BorderLayout.NORTH); add(scrollPane, BorderLayout.CENTER); add(textField, BorderLayout.SOUTH); pack(); }
From source file:edu.ku.brc.specify.config.FixDBAfterLogin.java
/** * // w w w . j a v a 2 s .co m */ public static void fixUserPermissions(final boolean doSilently) { final String FIXED_USER_PERMS = "FIXED_USER_PERMS"; boolean isAlreadyFixed = AppPreferences.getRemote().getBoolean(FIXED_USER_PERMS, false); if (isAlreadyFixed) { return; } String whereStr = " WHERE p.GroupSubClass = 'edu.ku.brc.af.auth.specify.principal.UserPrincipal' "; String whereStr2 = "AND p.userGroupScopeID IS NULL"; String postSQL = " FROM specifyuser su " + "INNER JOIN specifyuser_spprincipal ss ON su.SpecifyUserID = ss.SpecifyUserID " + "INNER JOIN spprincipal p ON ss.SpPrincipalID = p.SpPrincipalID " + "LEFT JOIN spprincipal_sppermission pp ON p.SpPrincipalID = pp.SpPrincipalID " + "LEFT OUTER JOIN sppermission pm ON pp.SpPermissionID = pm.SpPermissionID " + whereStr; String sql = "SELECT COUNT(*)" + postSQL + whereStr2; log.debug(sql); if (BasicSQLUtils.getCountAsInt(sql) < 1) { sql = "SELECT COUNT(*)" + postSQL; log.debug(sql); if (BasicSQLUtils.getCountAsInt(sql) > 0) { return; } } final String updatePermSQL = "DELETE FROM %s WHERE SpPermissionID = %d"; final String updatePrinSQL = "DELETE FROM %s WHERE SpPrincipalID = %d"; sql = "SELECT p.SpPrincipalID, pp.SpPermissionID" + postSQL; log.debug(sql); HashSet<Integer> prinIds = new HashSet<Integer>(); for (Object[] row : query(sql)) { Integer prinId = (Integer) row[0]; if (prinId != null) { prinIds.add(prinId); } Integer permId = (Integer) row[1]; if (permId != null) { update(String.format(updatePermSQL, "spprincipal_sppermission", permId)); update(String.format(updatePermSQL, "sppermission", permId)); log.debug("Removing PermId: " + permId); } } StringBuilder sb1 = new StringBuilder(); for (Integer prinId : prinIds) { update(String.format(updatePrinSQL, "specifyuser_spprincipal", prinId)); update(String.format(updatePrinSQL, "spprincipal", prinId)); log.debug("Removing PrinId: " + prinId); if (sb1.length() > 0) sb1.append(","); sb1.append(prinId.toString()); } log.debug("(" + sb1.toString() + ")"); // Create all the necessary UperPrincipal records // Start by figuring out what group there are and then create one UserPrincipal record // for each one TreeSet<String> nameSet = new TreeSet<String>(); sql = "SELECT su.Name, su.SpecifyUserID, p.userGroupScopeID, p.SpPrincipalID FROM specifyuser su " + "INNER JOIN specifyuser_spprincipal sp ON su.SpecifyUserID = sp.SpecifyUserID " + "INNER JOIN spprincipal p ON sp.SpPrincipalID = p.SpPrincipalID " + "WHERE p.GroupSubClass = 'edu.ku.brc.af.auth.specify.principal.GroupPrincipal'"; String fields = "TimestampCreated, TimestampModified, Version, GroupSubClass, groupType, Name, Priority, Remarks, userGroupScopeID, CreatedByAgentID, ModifiedByAgentID"; String insertSQL = "INSERT INTO spprincipal (" + fields + ") VALUES(?,?,?,?,?,?,?,?,?,?,?)"; String insertSQL2 = "INSERT INTO specifyuser_spprincipal (SpecifyUserID, SpPrincipalID) VALUES(?,?)"; String searchSql = "SELECT " + fields + " FROM spprincipal WHERE SpPrincipalID = ?"; sb1 = new StringBuilder(); PreparedStatement selStmt = null; PreparedStatement pStmt = null; PreparedStatement pStmt2 = null; try { Connection conn = DBConnection.getInstance().getConnection(); pStmt = conn.prepareStatement(insertSQL, Statement.RETURN_GENERATED_KEYS); pStmt2 = conn.prepareStatement(insertSQL2); selStmt = conn.prepareStatement(searchSql); String adtSQL = "SELECT DISTINCT ca.AgentID FROM specifyuser AS su INNER Join agent AS ca ON su.CreatedByAgentID = ca.AgentID"; Integer createdById = BasicSQLUtils.getCount(conn, adtSQL); if (createdById == null) { createdById = BasicSQLUtils.getCount(conn, "SELECT AgentID FROM agent ORDER BY AgentID ASC LIMIT 0,1"); if (createdById == null) { UIRegistry.showError("The permissions could not be fixed because there were no agents."); AppPreferences.shutdownAllPrefs(); DBConnection.shutdownFinalConnection(true, true); return; } } for (Object[] row : query(sql)) { String usrName = (String) row[0]; Integer userId = (Integer) row[1]; Integer collId = (Integer) row[2]; Integer prinId = (Integer) row[3]; nameSet.add(usrName); log.debug("usrName: " + usrName + " prinId: " + prinId); if (sb1.length() > 0) sb1.append(","); sb1.append(prinId.toString()); selStmt.setInt(1, prinId); ResultSet rs = selStmt.executeQuery(); if (rs.next()) { log.debug(String.format("%s - adding UserPrincipal for Collection %d / %d", usrName, rs.getInt(9), collId)); Integer createdByAgentID = (Integer) rs.getObject(10); Integer modifiedByAgentID = (Integer) rs.getObject(11); pStmt.setTimestamp(1, rs.getTimestamp(1)); pStmt.setTimestamp(2, rs.getTimestamp(2)); pStmt.setInt(3, 1); // Version pStmt.setString(4, "edu.ku.brc.af.auth.specify.principal.UserPrincipal"); // GroupSubClass pStmt.setString(5, null); // groupType pStmt.setString(6, rs.getString(6)); // Name pStmt.setInt(7, 80); // Priority pStmt.setString(8, rs.getString(8)); // Remarks pStmt.setInt(9, rs.getInt(9)); // userGroupScopeID pStmt.setInt(10, createdByAgentID != null ? createdByAgentID : createdById); pStmt.setInt(11, modifiedByAgentID != null ? modifiedByAgentID : createdById); // Create UserPrincipal pStmt.executeUpdate(); int newPrinId = BasicSQLUtils.getInsertedId(pStmt); // Join the new Principal to the SpecifyUser record pStmt2.setInt(1, userId); pStmt2.setInt(2, newPrinId); pStmt2.executeUpdate(); } else { // error } rs.close(); } log.debug("(" + sb1.toString() + ")"); AppPreferences.getRemote().putBoolean(FIXED_USER_PERMS, true); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (pStmt != null) pStmt.close(); if (pStmt2 != null) pStmt2.close(); if (selStmt != null) selStmt.close(); } catch (Exception ex) { } } final StringBuilder sb = new StringBuilder(); for (String nm : nameSet) { if (sb.length() > 0) sb.append('\n'); sb.append(nm); } if (!doSilently) { JTextArea ta = UIHelper.createTextArea(15, 30); ta.setText(sb.toString()); ta.setEditable(false); JEditorPane htmlPane = new JEditorPane("text/html", //$NON-NLS-1$ UIRegistry.getResourceString("FDBAL_PERMFIXEDDESC")); htmlPane.setEditable(false); htmlPane.setOpaque(false); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p:g,8px,f:p:g")); pb.add(htmlPane, cc.xy(1, 1)); pb.add(UIHelper.createScrollPane(ta), cc.xy(1, 3)); pb.setDefaultDialogBorder(); CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getMostRecentWindow(), UIRegistry.getResourceString("FDBAL_PERMFIXED"), true, CustomDialog.OK_BTN, pb.getPanel()); dlg.setOkLabel(UIRegistry.getResourceString("CLOSE")); UIHelper.centerAndShow(dlg); } }
From source file:hermes.browser.actions.AbstractFIXBrowserDocumentComponent.java
protected Component createPrettyPrintPanel(FIXMessage m) { final JTextArea textArea = new JTextArea(); textArea.setEditable(false);/*from w w w .j a v a 2 s. c om*/ textArea.setFont(Font.decode("Monospaced-PLAIN-12")); byte[] bytes = null; try { textArea.setText(FIXUtils.prettyPrint(m)); } catch (Throwable e) { textArea.setText(e.getMessage()); log.error("exception converting message to byte[]: ", e); } textArea.setCaretPosition(0); return SwingUtils.createJScrollPane(textArea); }
From source file:hermes.browser.actions.AbstractFIXBrowserDocumentComponent.java
protected Component createHexPanel(FIXMessage m) { final JTextArea textArea = new JTextArea(); textArea.setEditable(false);//w w w .j a v a2s. co m textArea.setFont(Font.decode("Monospaced-PLAIN-12")); byte[] bytes = null; try { textArea.setText(DumpUtils.dumpBinary(m.getBytes(), DumpUtils.DUMP_AS_HEX_AND_ALPHA)); } catch (Throwable e) { textArea.setText(e.getMessage()); log.error("exception converting message to byte[]: ", e); } textArea.setCaretPosition(0); final JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(textArea); return scrollPane; }
From source file:coreferenceresolver.gui.MarkupGUI.java
private JScrollPane newMarkupPanel(NounPhrase np, ReviewElement reviewElement) { //MODEL//from ww w .j a v a2 s . c om Element element = new Element(); //Newly added ScrollablePanel markupPanel = new ScrollablePanel(); markupPanel.setLayout(new BoxLayout(markupPanel, BoxLayout.X_AXIS)); markupPanel.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.FIT); JTextArea npContentTxtArea = new JTextArea(); npContentTxtArea.setEditable(false); npContentTxtArea.setText(((MarkupNounPhrase) np).content); markupPanel.add(npContentTxtArea); //REF SpinnerModel refSpinnerModel = new SpinnerNumberModel(np.getChainId(), -1, COLORS.length - 1, 1); JSpinner refSpinner = new JSpinner(refSpinnerModel); refSpinner.setValue(np.getChainId()); refSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { np.setChainId((int) refSpinner.getValue()); try { rePaint(reviewElements.get(np.getReviewId()), np); } catch (BadLocationException ex) { Logger.getLogger(MarkupGUI.class.getName()).log(Level.SEVERE, null, ex); } } }); element.refSpinner = refSpinner; //TYPE String[] typeValues = { "Object", "Other", "Candidate", "Attribute" }; SpinnerModel typeSpinnerModel = new SpinnerListModel(typeValues); JSpinner typeSpinner = new JSpinner(typeSpinnerModel); typeSpinner.setValue(typeValues[np.getType()]); element.typeSpinner = typeSpinner; //REF + TYPE ScrollablePanel spinners = new ScrollablePanel(); spinners.setLayout(new BoxLayout(spinners, BoxLayout.X_AXIS)); spinners.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.FIT); spinners.add(refSpinner); spinners.add(typeSpinner); markupPanel.add(spinners); reviewElement.addElement(element); JScrollPane scrollMarkupPanel = new JScrollPane(markupPanel); return scrollMarkupPanel; }