|
God I hate Java GUI work. HATE. So I've got this JFrame, let's call him 'happy'. Happy's just sitting there, chillin', he's got buttons and tabs and whatnot. In the same JVM, I start up a class which creates a ProcessBuilder and runs a process. Happy has nothing to do with any of this, can't see the ProcessBuilder, or the class that created it. This process started by ProcessBuilder has precious stdout and stderr InputStreams, which I gleefully want to display to the user in a brand spankin' new JFrame, let's call him 'motherfucker'. So the ProcessBuilder starts the process it's assigned to start and I spin up two threads to loop over the stdout and stderr I'm getting from that process. These two threads have the same instance of montherfucker, and in their loops are calling an append method to append their lines to a textarea sitting in motherfucker. Here's the code those two threads are using to gobble up all the stdout and stderr of the running process: code:
But wait! How am I appending lines to the textarea sitting in motherfucker? You bet your rear end I'm using SwingUtilities.invokeLater. Here's the append method sitting in motherfucker: code:
WHY?
|
# ? Jun 3, 2008 23:05 |
|
|
# ? May 8, 2024 07:10 |
|
epswing posted:WHY? You are looping over all the input / output in the seperate threads, but updating them all on the Event Dispatch thread (i.e. SwingUtilities.invokeLater(), which is the same no matter what JFrame you're using). Because you're looping over and invoking the Event Dispatch thread constantly it's locking up the other GUI. Could you not invoke the append() method at the end, and save the looping part in a StringBuilder or something? Like: code:
Twitchy fucked around with this message at 00:06 on Jun 4, 2008 |
# ? Jun 3, 2008 23:45 |
|
Well here's one for you: one of the processes I spawn and collect stdout/stderr from, well I just wrote a quick tcl script which prints hello, waits 45 seconds, prints goodbye, and exits. It looks like this:code:
Here's another one for you: If I comment out the contents of the append method in the motherfucker jframe (so, zero calls to invokeLater), I get the same behavior. code:
epswing fucked around with this message at 08:21 on Jun 4, 2008 |
# ? Jun 4, 2008 08:18 |
|
Twitchy posted:You are looping over all the input / output in the seperate threads, but updating them all on the Event Dispatch thread (i.e. SwingUtilities.invokeLater(), which is the same no matter what JFrame you're using). Because you're looping over and invoking the Event Dispatch thread constantly it's locking up the other GUI. Could you not invoke the append() method at the end, and save the looping part in a StringBuilder or something? Furthermore the invokeLater method just appends update events to the queue, unless there was a lot of events (which the last post shows that there really isn't) you can't really block the UI thread like that. And even then I don't think the effect would be the one shown there. epswing: I'm still worried that the stream reader stuff is running in the UI thread for some reason (the symptoms fit too well, dammit). Can you breakpoint on it (any line) in a debugger and check the full stacktrace doesn't have any Swing stuff in it?
|
# ? Jun 4, 2008 09:18 |
|
zootm posted:Batching the input would probably be a good idea, but waiting until the entire stream is read absolutely would not fit this use-case; it would only show anything once the processes had completely stopped. I guess you're right, I just assumed that because the GUI was noticably locking then the processes would have to have been taking a long time (therefore probably alot of lines to parse and a ton of events added to the queue). I just thought adding what could be thousands of events to the Event Queue could have an adverse effect, especially if alot of events are queued in front of his mouse click or whatever; I'm not exactly sure of the size of the input / output streams though. I didn't think the batching of the lines would be appropriate but it's an option, even having a progress bar would suffice if there were too many lines to process, especially since the user would only see lines whizzing past anyway. Edit: Doh, it just clicked on what he's trying to do, I guess it wouldn't be appropriate. Instead of doing a proper debug if you want the easy way to find out just do code:
epswing posted:Twitchy fucked around with this message at 11:32 on Jun 4, 2008 |
# ? Jun 4, 2008 11:17 |
|
Twitchy posted:Ah, it seems zootm is probably right, how are you making the threads? Twitchy posted:Instead of doing a proper debug if you want the easy way to find out just do
|
# ? Jun 4, 2008 12:53 |
|
Right before looping over the InputStreams I put a System.err.println("reading input " + input + " on thread " + Thread.currentThread().getName());. The output was:code:
How is this possible.
|
# ? Jun 4, 2008 16:31 |
|
I think that SwingUtilities.isEventDispatchThread() is exactly what you guys are looking for.
|
# ? Jun 4, 2008 16:32 |
|
epswing posted:Here's another one for you, the two jframes are basically two separate programs, each running in their own javaw.exe with their own main method, etc. It's possible that ProcessBuilder launches subprocesses which would still be run under the same JVM instance, so only 1 Event Dispatch thread would exist between processes; honestly I don't know enough about ProcessBuilder for it to be anything other than a guess. I know JFrames appear as their own application in Task Manager but I haven't checked if they run in a seperate process or not normally so i'll check that out later. Can you post the code you're using to launch the motherfucker process through ProcessBuilder? Twitchy fucked around with this message at 17:20 on Jun 4, 2008 |
# ? Jun 4, 2008 17:15 |
|
1337JiveTurkey posted:I think that SwingUtilities.isEventDispatchThread() is exactly what you guys are looking for. The thread creating the ProcessBuilder and both threads sucking up with stdout/err are isEventDispatchThread() == false. (<-- edit: typo) Twitchy: I guess I'll be putting together a working example, which is going to be a bitch, but at this point what choice do I have. I've removed the motherfucker jframe from the scenario completely and happy still freezes, inexplicably. I must have something else going wrong. I loving hate GUI/Swing work. This is the kind of stuff that makes me want to quit my job and go into pig farming. It's challenging, but for all the wrong reasons. epswing fucked around with this message at 18:38 on Jun 4, 2008 |
# ? Jun 4, 2008 17:29 |
|
epswing posted:The thread creating the ProcessBuilder and both threads sucking up with stdout/err are isEventDispatchThread() == true. epswing posted:I loving hate GUI/Swing work. This is the kind of stuff that makes me want to quit my job and go into pig farming. It's challenging, but for all the wrong reasons.
|
# ? Jun 4, 2008 17:42 |
|
epswing posted:The thread creating the ProcessBuilder and both threads sucking up with stdout/err are isEventDispatchThread() == true. zootm posted:Then the sucking threads are not being run in separate threads, they're running in the same thread as UI, for whatever reason. That result seems to mean that everything is running in the same thread. OH sorry, that should be isEventDispatchThread() == false. They're all false, all NOT on the event dispatch thread.
|
# ? Jun 4, 2008 18:37 |
|
Design question here.. I'm in the process of trying to put together a little app for fun.. I'm taking a file full of entries like these quote:2008/06/05 00:19:22 - Ardmore used -2 power at Megalith of Doom I'm attempting to build an app that will take a log full of entries like that and then build a player by player log that I can run operations on (For day 06/04 how much power did Ixion add, how much power did Ardmore use, etc). I'm sort of stumped as to the best way to tie this all together.. I'm thinking some sort of list with timestamp keys, or something, but I'm really not that familiar with the language. I've started with a hashtable of Player objects, it's the specifics of the Player object design that I just can't figure out a good approach. Peacefully Adrift fucked around with this message at 02:30 on Jun 5, 2008 |
# ? Jun 5, 2008 02:28 |
|
Where can I find the source code for an API library or whatever? I'm trying to find one of the packages in javax.swing but I haven't had much look with Google or looking in my own folders.
|
# ? Jun 5, 2008 05:11 |
|
Phillyt posted:Where can I find the source code for an API library or whatever? I'm trying to find one of the packages in javax.swing but I haven't had much look with Google or looking in my own folders. Look in your jdk directory (mine is C:\Program Files\Java\jdk1.6.0_02), I have a src.zip file with the entire java core.
|
# ? Jun 5, 2008 05:26 |
|
Phillyt posted:Where can I find the source code for an API library or whatever? I'm trying to find one of the packages in javax.swing but I haven't had much look with Google or looking in my own folders. If you have the JDK installed most IDE's will let you right click the Class name and goto the source code.
|
# ? Jun 5, 2008 10:38 |
|
Twitchy posted:If you have the JDK installed most IDE's will let you right click the Class name and goto the source code.
|
# ? Jun 5, 2008 12:19 |
|
I have a real bonehead beginner type question that I'm embarrassed to ask, but here goes:code:
Normally I'd achieve this type of thing by passing a variable between classes via method parameters, but given that this is all contained in the same class, I'm suddenly feeling very stupid (note- I'm all self taught and thus may be missing a few important fundamentals). Thanks in advance!
|
# ? Jun 9, 2008 18:00 |
|
The easist getaround for this is to move all your code from main() into the constructor, and then add a call to new ABC() in main().
|
# ? Jun 9, 2008 18:14 |
|
Use get and set methods instead.
|
# ? Jun 9, 2008 19:43 |
|
I'm trying to find some sort of spell checker source code so I can better learn hash trees. I Googled "open source Java spell checker" but I seem to only find really expensive ones for enterprise applications. Is there a good example of this that anyone knows of?
|
# ? Jun 10, 2008 08:29 |
|
Phillyt posted:I'm trying to find some sort of spell checker source code so I can better learn hash trees. I Googled "open source Java spell checker" but I seem to only find really expensive ones for enterprise applications. Is there a good example of this that anyone knows of? I'm not sure I understand the question, but why not just use a Java IDE like Netbeans (or Eclipse)? If you spell a variable wrong, it'll let you know. Apologies if that's not what you meant and I'm stating the obvious. Edit: Oh my face is red mister_gosh fucked around with this message at 18:28 on Jun 10, 2008 |
# ? Jun 10, 2008 18:20 |
|
http://www.devdaily.com/java/jwarehouse/jazzy/src/com/swabunga/spell/event/SpellChecker.java.shtml?
|
# ? Jun 10, 2008 18:25 |
|
mister_gosh posted:I'm not sure I understand the question, but why not just use a Java IDE like Netbeans (or Eclipse)? If you spell a variable wrong, it'll let you know. He wants the code for a spell checker, not a spell checker for his code
|
# ? Jun 10, 2008 18:26 |
|
BELL END posted:http://www.devdaily.com/java/jwarehouse/jazzy/src/com/swabunga/spell/event/SpellChecker.java.shtml? Thanks for that. I'll check it out.
|
# ? Jun 10, 2008 18:37 |
|
I can't get my JList to update. I'm going to have to get you guys on the payroll as it seems I can't get anything done without you guys. A huge thanks to everyone! I have a button in a JFrame class. When executed, it instantiates a popup JFrame and then passes it a class that has all the info I need to browse through the data: code:
code:
I have tried many variations of clearing the jList1 and repopulating it with no success. Thanks again in advance for any input you can provide! mister_gosh fucked around with this message at 19:08 on Jun 10, 2008 |
# ? Jun 10, 2008 18:56 |
|
You're only reassigning the field jList1; the original JList instance is still displayed in the UI. What you should really be doing is is assigning a DefaultListModel to jList1 once, never reconstructing jList1, and modifying the model (i.e. the DefaulListModel object) directly. For what it's worth you look like you're using Netbeans. Create a new property (i.e. a getter) for a ListModel instance on the main object and use that in the designer as the model for the element (there's a dropdown that'll let you select any property of the right type). Just have a field containing the (one!) DefaultListModel instance you're using, have the getter return that, and operate only on that. zootm fucked around with this message at 19:51 on Jun 10, 2008 |
# ? Jun 10, 2008 19:42 |
|
zootm posted:You're only reassigning the field jList1; the original JList instance is still displayed in the UI. What you should really be doing is is assigning a DefaultListModel to jList1 once, never reconstructing jList1, and modifying the model (i.e. the DefaulListModel object) directly. Thanks for the info. I am using Netbeans (6x) and trying to work through the interface to try to get it to do what you describe. I'll let you know how it goes once I find out how to create the property and find the dropdown (I think I've been staring too long at the screen!).
|
# ? Jun 10, 2008 20:21 |
|
mister_gosh posted:Thanks for the info. I am using Netbeans (6x) and trying to work through the interface to try to get it to do what you describe. I'll let you know how it goes once I find out how to create the property and find the dropdown (I think I've been staring too long at the screen!). Aswell as the reasons zootm said before, there is another major reason why it's not working at all: code:
code:
Twitchy fucked around with this message at 21:02 on Jun 10, 2008 |
# ? Jun 10, 2008 20:47 |
|
More explicitly, the property (along with the field) would look like this:code:
From then on just write your action handlers to update the model and the changes will be shown in the UI. You do not need to manually update the UI at all, Swing is pretty good for noticing changes in its underlying models and updating automatically. Edit: Here is the full source to an example which I just made in the UI designer, hopefully it'll be illustrative. The only methods I wrote are the ones detailed above and the content of the "hilarityButtonActionPerformed" method (the method itself was added by the designer). Incidentally I don't know how the binding stuff works in full but it might be possible to bind your data more directly to the "elements" property of the JList. zootm fucked around with this message at 21:05 on Jun 10, 2008 |
# ? Jun 10, 2008 21:02 |
|
Thanks guys. I'm getting somewhere (with setting the property/getter) but need to put it down for a couple hours to tend to life outside of work. I'll report back. Again, I really appreciate the time!!
|
# ? Jun 10, 2008 21:08 |
|
zootm posted:Edit: Here is the full source to an example which I just made in the UI designer, hopefully it'll be illustrative. The only methods I wrote are the ones detailed above and the content of the "hilarityButtonActionPerformed" method (the method itself was added by the designer). Incidentally I don't know how the binding stuff works in full but it might be possible to bind your data more directly to the "elements" property of the JList. Wow, thanks again for everything! I got my class files all set up using essentially the same code you pasted, and then compiled and got: quote:Netbeans came out of the closet to say: I'm getting this error because the jar I'm building stupidly requires a jar built under Java 1.4 due to the proprietary API I am using within it...if I compile using 1.6, it works fine, but then I'll break the API calls.
|
# ? Jun 11, 2008 00:00 |
|
Ok, thanks again. I got it to work using almost the same code in Netbeans 5. Something in the bindings methods of Netbeans 6 requires it to be compiled in Java 1.5 (surprisingly not the entire swing-layout-1.0.3.jar). Netbeans 5 definitely isn't as nice but it's still a lot better than building AWT from scratch Thank you, thank you, thank you!
|
# ? Jun 11, 2008 03:38 |
|
No problem. Incidentally, though, Java 5 and 6 can call 1.4 JARs without any problem at all; unless you need the code you produce to run on 1.4 or earlier it shouldn't be an issue at all.
|
# ? Jun 11, 2008 09:30 |
|
While we're discussing Netbeans, what are people's feelings or experiences with (desktop, GUI) application frameworks? I've got a few programs to write in my future and have been checking out some of the choices. As these applications will end up on MacOS (in addition to other platforms), I've been looking for document-centric toolkits (i.e. an application has multiple documents each in it's own window) but there seems to be only single window or project-centric options. Things I've looked at: * JIDE / JDAF: nice but commercial, which doesn't suit for reasons other than money. * Swing Application Framework / SAF / JSR 296: looks like it might be the go, although I'm still getting my head around it. * Netbeans: impressive, although it seems to be mostly angled towards producing applications that look and behave like Netbeans. * Eclipse: couldn't make heads or tails of it. * Jazz: commercial but it might allow FOSS use. * QtJambi: I like Qt, and this produces visually appealing apps. * Various small projects: aloe, spar, Skeleton. Any other ideas or opinions?
|
# ? Jun 11, 2008 13:40 |
|
Netbeans, using its newer Swing Application Framework stuff, is very good at making SAF apps. I assume your other Netbeans entry is the Netbeans framework itself, which is neat but only really for apps which are a lot like Netbeans, like you state. Eclipse is much the same when used as a framework. I wouldn't go with QtJambi since I'm not a big fan of Qt, although as you say it might fit well with you since you do like the framework. Swing has the advantage of (these days) integrating very well with both Windows and Linux (GTK+) systems; the OS X stuff is nice too but Apple provide it themselves and it can be a little slow. Pre-Qt4 I'm not sure how great Qt is across platforms. zootm fucked around with this message at 14:27 on Jun 11, 2008 |
# ? Jun 11, 2008 14:23 |
EDIT: Nevermind, resolved.
Farchanter fucked around with this message at 05:02 on Jun 16, 2008 |
|
# ? Jun 15, 2008 22:43 |
|
I have some code that queries a UDDI registry at runtime and returns the wsdl address. Now in a language like ruby I can just pass that url into a function and start calling the methods of the web service. I am sure this is possible in Java but every resource I have found so far talks about generating the classes to interact with the web service at build time. Is dynamic run time service binding or whatever you want to call it possible in java and if so how?
|
# ? Jun 19, 2008 19:27 |
Is there a way to define an operator in java? It's not really necessary for what I'm doing, I was just curious... Instead of: ArrayList<Double> pointsList = divide(aggregatedPoints, dataSetSum); Doing something like: ArrayList<Double> pointsList = aggregatedPoints/dataSetSum;
|
|
# ? Jun 19, 2008 23:16 |
|
|
# ? May 8, 2024 07:10 |
|
fletcher posted:ArrayList<Double> pointsList = aggregatedPoints/dataSetSum;
|
# ? Jun 19, 2008 23:21 |