List of usage examples for javax.swing JTextArea JTextArea
public JTextArea()
From source file:edu.smc.mediacommons.panels.SecurityPanel.java
public SecurityPanel() { setLayout(null);/*w w w. j a va 2s.c o m*/ FILE_CHOOSER = new JFileChooser(); JButton openFile = Utils.createButton("Open File", 10, 20, 100, 30, null); add(openFile); JButton saveFile = Utils.createButton("Save File", 110, 20, 100, 30, null); add(saveFile); JButton decrypt = Utils.createButton("Decrypt", 210, 20, 100, 30, null); add(decrypt); JButton encrypt = Utils.createButton("Encrypt", 310, 20, 100, 30, null); add(encrypt); JTextField path = Utils.createTextField(10, 30, 300, 20); path.setText("No file selected"); final JTextArea viewer = new JTextArea(); JScrollPane pastePane = new JScrollPane(viewer); pastePane.setBounds(15, 60, 400, 200); add(pastePane); openFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (FILE_CHOOSER.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { File toRead = FILE_CHOOSER.getSelectedFile(); if (toRead == null) { JOptionPane.showMessageDialog(getParent(), "The input file does not exist!", "Opening Failed...", JOptionPane.WARNING_MESSAGE); } else { try { List<String> lines = IOUtils.readLines(new FileInputStream(toRead), "UTF-8"); viewer.setText(""); for (String line : lines) { viewer.append(line); } } catch (IOException ex) { } } } } }); saveFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (FILE_CHOOSER.showSaveDialog(getParent()) == JFileChooser.APPROVE_OPTION) { File toWrite = FILE_CHOOSER.getSelectedFile(); Utils.writeToFile(viewer.getText(), toWrite); JOptionPane.showMessageDialog(getParent(), "The file has now been saved to\n" + toWrite.getPath()); } } }); encrypt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String password = Utils.getPasswordInput(getParent()); if (password != null) { try { BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor(); basicTextEncryptor.setPassword(password); String text = basicTextEncryptor.encrypt(viewer.getText()); viewer.setText(text); } catch (Exception ex) { JOptionPane.showMessageDialog(getParent(), "Could not encrypt the text, an unexpected error occurred.", "Encryption Failed...", JOptionPane.WARNING_MESSAGE); } } else { JOptionPane.showMessageDialog(getParent(), "Could not encrypt the text, as no\npassword has been specified.", "Encryption Failed...", JOptionPane.WARNING_MESSAGE); } } }); decrypt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String password = Utils.getPasswordInput(getParent()); if (password != null) { try { BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor(); basicTextEncryptor.setPassword(password); String text = basicTextEncryptor.decrypt(viewer.getText()); viewer.setText(text); } catch (Exception ex) { JOptionPane.showMessageDialog(getParent(), "Could not decrypt the text, an unexpected error occurred.", "Decryption Failed...", JOptionPane.WARNING_MESSAGE); } } else { JOptionPane.showMessageDialog(getParent(), "Could not decrypt the text, as no\npassword has been specified.", "Decryption Failed...", JOptionPane.WARNING_MESSAGE); } } }); }
From source file:com.emr.schemas.DestinationTables.java
/** * Creates a new DestinationTables form. * @param sourceQuery {@link String} SQL Query for getting the source data. * @param selected_columns {@link List} List containing the selected source columns * @param sourceTables {@link List} List containing the source tables * @param relations {@link String} Relationship between the source tables * @param emrConn {@link Connection} KenyaEMR Database Connection object *//*ww w. j a v a2 s .c o m*/ public DestinationTables(String sourceQuery, List selected_columns, List sourceTables, String relations, Connection emrConn, TableRelationsForm parent) { fileManager = null; dbManager = null; mpiConn = null; this.parent = parent; this.sourceQuery = sourceQuery; this.selected_columns = selected_columns; this.sourceTables = sourceTables; this.relations = relations; this.emrConn = emrConn; listModel = new DefaultListModel<String>(); initComponents(); this.setClosable(true); SourceTablesListener listSelectionListener = new SourceTablesListener(new JTextArea(), listOfTables); destinationTablesList.setCellRenderer(new CheckboxListCellRenderer()); destinationTablesList.addListSelectionListener(listSelectionListener); destinationTablesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //Create KenyaEMR DB connection fileManager = new FileManager(); String[] settings = fileManager.getConnectionSettings("mpi_database.properties", "mpi"); if (settings == null) { //Connection settings not found //Open MPIConnectionForm JOptionPane.showMessageDialog(null, "Database Settings not found. Please set the connection settings for the database first.", "MPI Database settings", JOptionPane.ERROR_MESSAGE); } else { if (settings.length < 1) { //Open MPIConnectionForm JOptionPane.showMessageDialog(null, "Database Settings not found. Please set the connection settings for the database first.", "MPI Database settings", JOptionPane.ERROR_MESSAGE); } else { //Connection settings are ok //We establish a connection dbManager = new DatabaseManager(settings[0], settings[1], settings[3], settings[4], settings[5]); mpiConn = dbManager.getConnection(); if (mpiConn == null) { JOptionPane.showMessageDialog(null, "Test Connection Failed", "Connection Test", JOptionPane.ERROR_MESSAGE); } else { //get emr schema getDatabaseMetaData(); } } } }
From source file:com.mycompany.listBoxer.panel.ListBoxerForm.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor.// ww w. ja v a 2 s . co m * * @throws ParseException */ @SuppressWarnings({ "unchecked", "rawtypes" }) // <editor-fold defaultstate="collapsed" // desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() throws ParseException { buttonGroup1 = new javax.swing.ButtonGroup(); buttonGroup2 = new javax.swing.ButtonGroup(); RangeComboBox = new javax.swing.JComboBox(); jLabel1 = new javax.swing.JLabel(); jTextField1 = new JFormattedTextField(); AddButton = new javax.swing.JButton(); AscendingRadioButton = new javax.swing.JRadioButton(); DescendingRadioButton = new javax.swing.JRadioButton(); jTextField2 = new JTextArea(); ClearButton = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); RecordsLabel = new javax.swing.JLabel(); TotalLabel = new javax.swing.JLabel(); AlphabeticCheckBox = new javax.swing.JCheckBox(); NumericCheckBox = new javax.swing.JCheckBox(); CombinedCheckBox = new javax.swing.JCheckBox(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); MainMenu = new javax.swing.JMenuBar(); FileMenuItem = new javax.swing.JMenu(); OpenItem = new javax.swing.JMenuItem(); SaveItem = new javax.swing.JMenuItem(); ExitItem = new javax.swing.JMenuItem(); EditMenuItem = new javax.swing.JMenu(); UndoItem = new javax.swing.JMenuItem(); jSeparator2 = new javax.swing.JPopupMenu.Separator(); CutItem = new javax.swing.JMenuItem(); CopyItem = new javax.swing.JMenuItem(); PasteItem = new javax.swing.JMenuItem(); HelpMenuItem = new javax.swing.JMenu(); AboutItem = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); List<String> rangeList = RangeType.getStringValue(); String[] arrays = new String[rangeList.size()]; RangeComboBox.setModel(new javax.swing.DefaultComboBoxModel(rangeList.toArray(arrays))); RangeComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { justDoIt(); } private void justDoIt() { if (NumericCheckBox.isSelected()) { } else if (AlphabeticCheckBox.isSelected()) { } else { } } }); jLabel1.setText("Range"); jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField1ActionPerformed(evt); } }); jTextField2.setEditable(Boolean.FALSE); AddButton.setText("Add to list"); AddButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AddButtonActionPerformed(evt); } }); buttonGroup1.add(AscendingRadioButton); AscendingRadioButton.setText("Ascending"); AscendingRadioButton.setBorder(javax.swing.BorderFactory.createTitledBorder("Sort Order")); AscendingRadioButton.setName("Sort Order"); // NOI18N buttonGroup1.add(DescendingRadioButton); DescendingRadioButton.setText("Descending"); DescendingRadioButton.setBorder(javax.swing.BorderFactory.createTitledBorder("Sort Order")); DescendingRadioButton.setName("Sort Order"); // NOI18N ClearButton.setText("Clear list"); ClearButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { ClearButtonActionPerformed(event); } }); jLabel2.setText("Records in list : "); jLabel3.setText("Total records : "); RecordsLabel.setText("0"); TotalLabel.setText("0"); buttonGroup2.add(AlphabeticCheckBox); AlphabeticCheckBox.setText("Alphabetic"); AlphabeticCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { AlphabeticCheckBoxActionPerformed(evt); } }); buttonGroup2.add(NumericCheckBox); NumericCheckBox.setText("Numeric"); NumericCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NumericCheckBoxActionPerformed(e); } }); buttonGroup2.add(CombinedCheckBox); CombinedCheckBox.setText("Combined"); CombinedCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CombinedCheckBoxActionPerformed(e); } }); jLabel6.setText("Symbols :"); jLabel7.setText("Sort order :"); MainMenu.setName(""); // NOI18N MainMenu.setRequestFocusEnabled(false); FileMenuItem.setText("File"); OpenItem.setText("Open"); FileMenuItem.add(OpenItem); SaveItem.setText("Save as"); FileMenuItem.add(SaveItem); ExitItem.setText("Exit"); FileMenuItem.add(ExitItem); MainMenu.add(FileMenuItem); EditMenuItem.setText("Edit"); UndoItem.setText("Undo"); EditMenuItem.add(UndoItem); EditMenuItem.add(jSeparator2); CutItem.setText("Cut"); EditMenuItem.add(CutItem); CopyItem.setText("Copy"); EditMenuItem.add(CopyItem); PasteItem.setText("Paste"); EditMenuItem.add(PasteItem); MainMenu.add(EditMenuItem); HelpMenuItem.setText("Help"); AboutItem.setText("About ListBoxer"); HelpMenuItem.add(AboutItem); MainMenu.add(HelpMenuItem); setJMenuBar(MainMenu); MainMenu.getAccessibleContext().setAccessibleName(""); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jLabel1).addGap(22, 22, 22) .addComponent(RangeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(AlphabeticCheckBox).addComponent(NumericCheckBox) .addComponent(CombinedCheckBox).addComponent(jLabel6).addComponent(jLabel7))) .addComponent(AscendingRadioButton).addComponent(DescendingRadioButton, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(44, 44, 44) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup().addComponent(jLabel3).addGap(0, 53, Short.MAX_VALUE)) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(AddButton, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE) .addComponent(ClearButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(21, 21, 21)) .addGroup(layout.createSequentialGroup() .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(TotalLabel) .addGroup(layout.createSequentialGroup().addComponent(jLabel2) .addGap(18, 18, 18).addComponent(RecordsLabel))) .addContainerGap(26, Short.MAX_VALUE))))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(19, 19, 19).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(RangeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(AddButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(32, 32, 32) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(ClearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(RecordsLabel)) .addGap(18, 18, 18) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3).addComponent(TotalLabel)) .addGap(38, 38, 38)) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(17, 17, 17) .addComponent(jLabel7).addGap(1, 1, 1) .addComponent(AscendingRadioButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(DescendingRadioButton, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(69, 69, 69).addComponent(jLabel6) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(AlphabeticCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(NumericCheckBox) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(CombinedCheckBox))) .addGap(0, 22, Short.MAX_VALUE))))); pack(); }
From source file:ComponentEventDemo.java
public ComponentEventDemo() { super(new BorderLayout()); display = new JTextArea(); display.setEditable(false);/*from ww w .j av a 2s . co m*/ JScrollPane scrollPane = new JScrollPane(display); scrollPane.setPreferredSize(new Dimension(350, 200)); JPanel panel = new JPanel(new BorderLayout()); label = new JLabel("This is a label", JLabel.CENTER); label.addComponentListener(this); panel.add(label, BorderLayout.CENTER); JCheckBox checkbox = new JCheckBox("Label visible", true); checkbox.addItemListener(this); checkbox.addComponentListener(this); panel.add(checkbox, BorderLayout.PAGE_END); panel.addComponentListener(this); add(scrollPane, BorderLayout.CENTER); add(panel, BorderLayout.PAGE_END); frame.addComponentListener(this); }
From source file:GridBagLayoutTest.java
public FontFrame() { setTitle("GridBagLayoutTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); GridBagLayout layout = new GridBagLayout(); setLayout(layout);/* w w w . j a v a 2 s. c o m*/ ActionListener listener = new FontAction(); // construct components JLabel faceLabel = new JLabel("Face: "); face = new JComboBox(new String[] { "Serif", "SansSerif", "Monospaced", "Dialog", "DialogInput" }); face.addActionListener(listener); JLabel sizeLabel = new JLabel("Size: "); size = new JComboBox(new String[] { "8", "10", "12", "15", "18", "24", "36", "48" }); size.addActionListener(listener); bold = new JCheckBox("Bold"); bold.addActionListener(listener); italic = new JCheckBox("Italic"); italic.addActionListener(listener); sample = new JTextArea(); sample.setText("The quick brown fox jumps over the lazy dog"); sample.setEditable(false); sample.setLineWrap(true); sample.setBorder(BorderFactory.createEtchedBorder()); // add components to grid, using GBC convenience class add(faceLabel, new GBC(0, 0).setAnchor(GBC.EAST)); add(face, new GBC(1, 0).setFill(GBC.HORIZONTAL).setWeight(100, 0).setInsets(1)); add(sizeLabel, new GBC(0, 1).setAnchor(GBC.EAST)); add(size, new GBC(1, 1).setFill(GBC.HORIZONTAL).setWeight(100, 0).setInsets(1)); add(bold, new GBC(0, 2, 2, 1).setAnchor(GBC.CENTER).setWeight(100, 100)); add(italic, new GBC(0, 3, 2, 1).setAnchor(GBC.CENTER).setWeight(100, 100)); add(sample, new GBC(2, 0, 1, 4).setFill(GBC.BOTH).setWeight(100, 100)); }
From source file:uk.co.markfrimston.tasktree.Main.java
public Main(TaskTree taskTree) { super();/*from ww w. j a v a 2 s .c o m*/ this.taskTree = taskTree; this.setTitle("Task Tree"); this.setSize(new Dimension(300, 500)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel quickInPanel = new JPanel(new BorderLayout()); this.quickIn = new JTextArea(); this.quickIn.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_ENTER) { String newText = quickIn.getText().trim(); if (newText != null && newText.length() > 0) { addTask(Main.this.taskTree.getRoot(), 0, newText, true); try { Main.this.taskTree.changesMade(); } catch (Exception e) { error(e.getMessage()); } } quickIn.setText(""); } } }); this.quickIn.setPreferredSize(new Dimension(300, 75)); this.quickIn.setBorder(BorderFactory.createTitledBorder("Quick Input")); quickInPanel.add(this.quickIn, BorderLayout.CENTER); this.syncButton = new JButton("Sync"); this.syncButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new SyncThread(Main.this).start(); } }); quickInPanel.add(this.syncButton, BorderLayout.EAST); this.getContentPane().add(quickInPanel, BorderLayout.NORTH); this.tree = new JTree(taskTree.getTreeModel()); DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object newVal = htmlFilter(String.valueOf(node.getUserObject())); if (node.getChildCount() > 0 && !tree.isExpanded(new TreePath(node.getPath()))) { DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) node.getFirstLeaf(); newVal = htmlFilter(String.valueOf(node.getUserObject())) + " <span style='color:silver;font-style:italic'>" + "(" + String.valueOf(firstLeaf.getUserObject()) + ")</span>"; } newVal = "<html>" + newVal + "</html>"; return super.getTreeCellRendererComponent(tree, newVal, selected, expanded, leaf, row, hasFocus); } }; ImageIcon bulletIcon = new ImageIcon(Main.class.getResource("bullet.gif")); renderer.setLeafIcon(bulletIcon); renderer.setOpenIcon(bulletIcon); renderer.setClosedIcon(bulletIcon); renderer.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0)); this.tree.setCellRenderer(renderer); this.tree.setRootVisible(false); this.tree.setShowsRootHandles(true); this.tree.addMouseListener(new MouseAdapter() { protected void doSelectRow(MouseEvent arg0) { int row = tree.getRowForLocation(arg0.getX(), arg0.getY()); if (row != -1) { tree.setSelectionRow(row); if (arg0.isPopupTrigger()) { popup.show(tree, arg0.getX(), arg0.getY()); } } } public void mousePressed(MouseEvent arg0) { doSelectRow(arg0); } public void mouseReleased(MouseEvent arg0) { doSelectRow(arg0); } }); JScrollPane treeScroll = new JScrollPane(tree); treeScroll.setBorder(BorderFactory.createTitledBorder("Task List")); this.getContentPane().add(treeScroll, BorderLayout.CENTER); this.popup = new JPopupMenu(); JMenuItem addBefore = new JMenuItem("Add Before"); addBefore.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = parent.getIndex(selected); promptAndInsert(parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(addBefore); JMenuItem addAfter = new JMenuItem("Add After"); addAfter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = parent.getIndex(selected) + 1; promptAndInsert(parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(addAfter); JMenuItem addNested = new JMenuItem("Add Nested"); addNested.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); int pos = selected.getChildCount(); promptAndInsert(selected, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { ex.getMessage(); } } }); this.popup.add(addNested); this.popup.add(new JSeparator()); JMenuItem moveTop = new JMenuItem("Move to Top"); moveTop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); moveTask(selected, parent, 0); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveTop); JMenuItem moveUp = new JMenuItem("Move Up"); moveUp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = Math.max(parent.getIndex(selected) - 1, 0); moveTask(selected, parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveUp); JMenuItem moveDown = new JMenuItem("Move Down"); moveDown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = Math.min(parent.getIndex(selected) + 1, parent.getChildCount() - 1); moveTask(selected, parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveDown); JMenuItem moveBottom = new JMenuItem("Move to Bottom"); moveBottom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); moveTask(selected, parent, parent.getChildCount() - 1); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveBottom); this.popup.add(new JSeparator()); JMenuItem rename = new JMenuItem("Edit"); rename.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); String newText = prompt((String) selected.getUserObject()); if (newText != null && newText.length() > 0) { selected.setUserObject(newText); Main.this.taskTree.getTreeModel().reload(selected); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } } }); this.popup.add(rename); JMenuItem delete = new JMenuItem("Delete"); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { promptAndRemove(getSelectedNode()); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(delete); this.setVisible(true); loadConfig(); load(); syncButton.setVisible(this.taskTree.hasSyncCapability()); }
From source file:com.cactus.ClientChatGUI.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor./*from w w w . j a v a2s. c o m*/ */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { Message_Area = new JTextField(); Send_Button = new JButton(); Back_Button = new JButton(); jScrollPane1 = new JScrollPane(); Chat_Area = new JTextArea(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Send_Button.setText("Send"); Send_Button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { Send_ButtonActionPerformed(evt); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); Chat_Area.setColumns(20); Chat_Area.setRows(5); Chat_Area.setEditable(false); jScrollPane1.setViewportView(Chat_Area); try { updateChatBox(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } Back_Button.setText("Back"); Back_Button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Back_ButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new GroupLayout(getContentPane()); layout.setHorizontalGroup(layout.createParallelGroup(Alignment.TRAILING).addGroup(layout .createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(Alignment.TRAILING) .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent( Message_Area, GroupLayout.PREFERRED_SIZE, 337, GroupLayout.PREFERRED_SIZE) .addGap(18) .addGroup(layout.createParallelGroup(Alignment.TRAILING, false) .addComponent(Back_Button, 0, 0, Short.MAX_VALUE).addComponent(Send_Button, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(Alignment.TRAILING).addGroup(layout .createSequentialGroup().addContainerGap() .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE).addGap(18) .addGroup(layout.createParallelGroup(Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(Send_Button) .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Back_Button)) .addComponent(Message_Area, GroupLayout.PREFERRED_SIZE, 68, GroupLayout.PREFERRED_SIZE)) .addContainerGap())); getContentPane().setLayout(layout); pack(); }
From source file:serial.ChartFromSerial.java
/** * Creates new form JavaArduinoInterfacingAttempt *//*from www. j a v a 2 s . c o m*/ public ChartFromSerial() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { System.out.println(e); } initComponents(); //set autoscroll autoScroll_chkBx.setSelected(true); autoScrollEnabled = true; //create the graph defaultSeries = new XYSeries(graphName); defaultDataset = new XYSeriesCollection(defaultSeries); defaultChart = ChartFactory.createXYLineChart(graphName, xAxisLabel, yAxisLabel, defaultDataset); graph = new ChartPanel(defaultChart); chartPanel.add(graph, BorderLayout.CENTER); graph.setVisible(true); //create the text log text = new JTextArea(); text.setEditable(false); textScrollPane = new JScrollPane(text); textScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); textPanel.add(textScrollPane, BorderLayout.CENTER); textScrollPane.setVisible(true); //Populate the combo box portNames = SerialPort.getCommPorts(); while (portNames.length == 0) { if (JOptionPane.showConfirmDialog(rootPane, "No connected devices found.\nWould you like to refresh?", "Could not connect to any devices.", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.NO_OPTION) { buttonsOff(); return; } else { portNames = SerialPort.getCommPorts(); } } portList_jCombo.removeAllItems(); for (SerialPort portName : portNames) { portList_jCombo.addItem(portName.getSystemPortName()); } }
From source file:gtu._work.ui.ObnfCheckPDFErrorUI.java
private void initGUI() { try {/*from w w w .j av a 2 s. com*/ JCommonUtil.frameCloseConfirm(this); BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("log", null, jPanel2, null); { jScrollPane2 = new JScrollPane(); jPanel2.add(jScrollPane2, BorderLayout.CENTER); { logArea = new JTextArea(); jScrollPane2.setViewportView(logArea); } } { checkBtn = new JButton(); jPanel2.add(checkBtn, BorderLayout.SOUTH); checkBtn.setText("\u6aa2\u67e5"); checkBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { checkBtnActionPerformed(); } }); } } } pack(); this.setSize(542, 394); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }
From source file:biomine.bmvis2.pipeline.sources.QueryGraphSource.java
@Override public BMGraph getBMGraph() throws GraphOperationException { try {//w w w.j a v a2 s . c om 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; }