| | |
Table Listeners
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2005
Posts: 20
Reputation:
Solved Threads: 0
Hi,
i was wondering if you could help me. i am having a problem with a listener in SWT. i have a program where the user enters some text in a textfield and then clicks on a browse button where they select the directory they want the program to search for this string. the user then clicks a submit button. what happens here is that it will only return the files that contain that string and i have them outputting to an SWT table. the problem i am having is that i would like the user to be able to click on one of the files in the table and get it to open. however when i do this it opens all files in the table instead of just the one i picked. i think its because i have a mouse listener on the table instead of on the TableItem. however when i went to do it on the table item i could't figure out what the parameters where meant to be.
Can you please please help me. i am really stuck and have spent two days trying to get it to work with no success. it is part of my final year project.
thanks in advanced
scoobie.
here is the code i am using:
i was wondering if you could help me. i am having a problem with a listener in SWT. i have a program where the user enters some text in a textfield and then clicks on a browse button where they select the directory they want the program to search for this string. the user then clicks a submit button. what happens here is that it will only return the files that contain that string and i have them outputting to an SWT table. the problem i am having is that i would like the user to be able to click on one of the files in the table and get it to open. however when i do this it opens all files in the table instead of just the one i picked. i think its because i have a mouse listener on the table instead of on the TableItem. however when i went to do it on the table item i could't figure out what the parameters where meant to be.
Can you please please help me. i am really stuck and have spent two days trying to get it to work with no success. it is part of my final year project.
thanks in advanced
scoobie.
here is the code i am using:
Java Syntax (Toggle Plain Text)
private void addFile(final String searchPattern, final File file, boolean subdirs, boolean first) { System.out.println("In add file"); if (file.isFile()) { if (containsPattern(file.toString(), searchPattern)) { System.out.println(file); // Need to add to model in event thread EventQueue.invokeLater(new Runnable() { public void run() {} }); Results(searchPattern, file); } } //end if else if (file.isDirectory()) { if (first || subdirs) { // need to let first pass through File files[] = file.listFiles(); for (int i = 0; i < files.length; i++) { addFile(searchPattern, files[i], subdirs, false); } //end for loop } } }//end addFile public void Results(final String searchPattern, final File file) { final String files = file.toString(); TableItem tableItem = new TableItem(rsTable, SWT.NONE); tableItem.setText(files); rsTable.addMouseListener(new MouseListener() { public void mouseDoubleClick(MouseEvent arg0) { System.out.println("ShowHighlighted"); // Don't block the event thread new Thread() { public void run() { final JDialog dialog = new JDialog(); Container contentPane = dialog.getContentPane(); try { FileReader reader = new FileReader(files); JTextPane textPane = new JTextPane(); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); contentPane.add(scrollPane); // Read in file textPane.read(reader, null); // Make highlight attribute final SimpleAttributeSet set = new SimpleAttributeSet(); set.addAttribute( StyleConstants.CharacterConstants.Bold, Boolean.TRUE); // Get Document for text pane final DefaultStyledDocument document = (DefaultStyledDocument)textPane.getDocument(); // Handle newlines across platforms document.putProperty( DefaultEditorKit.EndOfLineStringProperty, "\n"); // highlight areas String text = textPane.getText(); Pattern thePattern = Pattern.compile(searchPattern); final Matcher matcher = thePattern.matcher(text); EventQueue.invokeLater(new Runnable() { public void run() { while (matcher.find()) { int start = matcher.start(); int length = matcher.end() - start; document.setCharacterAttributes(start, length, set, false); }// end while // show results dialog.setSize(300, 300); dialog.show(); }//end inside run } //end invokeQ ); } //end try catch (IOException ex) { System.err.println("Unable to show highlights" + ex); }//end catch }//end outside run } //end thread .start(); } public void mouseDown(MouseEvent arg0) { } public void mouseUp(MouseEvent arg0) { } }); filePath.pack(); // column rsTable.pack(); //table } //end results method
![]() |
Similar Threads
- Copying table from one mdb to another (ASP)
- Need help with HTMl Table echoing? (PHP)
- Table of Contents Script (Java)
Other Threads in the Java Forum
- Previous Thread: how to move an jlabel icon from one jlabel to another jlabel
- Next Thread: Hello world for mobile applications
Views: 2990 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component consumer database desktop developmenthelp draw eclipse encode error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javac javaee javaprojects jmf jni jpanel julia lego linked linux list loop mac map method methods mobile netbeans newbie number object online oracle print printf problem program programming project properties recursion researchinmotion rotatetext rsa scanner score screen server set size sms socket sort sql string swing template test threads time transfer tree update windows working xstream





