|
-
July 21st, 2009, 01:26 PM
#16
Re: GUI .jar problems
Hey postmortem - That didn't solve it man.
So, here is what happens:
Code:
private void addActionPerformed(java.awt.event.ActionEvent evt) {
// Setting the busy cursor
topAndConsoleSplit.setCursor(new Cursor(Cursor.WAIT_CURSOR));
//Long function reads a file and adds data to mysql
addToMySQL();
//Resetting back to the normal curson
topAndConsoleSplit.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
The cursor doesn't reset and always stays busy after the button has been pressed (Action fired). I was reading around and this is a common issue, I think I need to create a new "thread" for the function that adds the dataToMySQL?
-
July 22nd, 2009, 01:18 AM
#17
Re: GUI .jar problems
if you add new function, then changing cursor will have to be done from GUI thread, not from newly created thread.
-
July 22nd, 2009, 05:39 AM
#18
Re: GUI .jar problems
Coding Tip:
When temporarily changing the cursor you should wrap the code between the setCursor calls in a try clause and add the code changing the cursor back to the original value to a finally clause.
If you don't do this and your code throws a non-fatal exception the application will continue but the cursor will not be changed back to the original cursor. In your case the cursor will remain as the wait cursor which is very annoying and confusing for the user.
-
July 22nd, 2009, 08:15 AM
#19
Re: GUI .jar problems
Another coding tip:
Unless you're defining your own cursor types, it's more efficient to use the pre-defined cursors than create new ones:
Code:
Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
The best is the enemy of the good...
Voltaire
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
July 22nd, 2009, 08:17 AM
#20
Re: GUI .jar problems
 Originally Posted by postmortem
if you add new function, then changing cursor will have to be done from GUI thread, not from newly created thread.
Hey postmortem - Can you give me an example of how I would go about using the GUI thread? Isn't it the same as a default thread?
Oh, I wasn't trying to change the cursor in a new thread, I was trying to add the addToMySQL function to the new thread. This is because after I click the button, it gets stuck to the wait cursor but it doesn't add anything to the mySQL table as it is supposed to with the function.
@ Keang - Thanks for the tip! I did enclose my code within a try/catch block. Now it changes the cursor back to the deafault cursor. But it still doesn't execute my function when I'm trying to run it through the .jar file. It executes it when running it via netbeans though. Additionally, I'm very certain that all the libraries are included this time.
Code:
try { // Setting the busy cursor
topAndConsoleSplit.setCursor(new Cursor(Cursor.WAIT_CURSOR));
addToMySQL();
} catch (Exception cursorChange) {
System.out.println(" -- " + cursorChange.getMessage());
}
finally { //Resetting back to the normal curson
topAndConsoleSplit.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
-
July 22nd, 2009, 08:27 AM
#21
Re: GUI .jar problems
Do you get any exceptions? I would expect that if a required class or resource is not available, you'd get an exception thrown when you try to create or access or use it. Check your code to make sure you are not ignoring possible exceptions with empty catch blocks.
If all the required libraries are included, yet a class or resource in one of those libraries isn't available, it is probably a problem with the manifest file. See Working With Manifest Files.
The outcome of any serious research can only be to make two questions grow where only one grew before...
T. Veblen
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
July 22nd, 2009, 09:42 AM
#22
Re: GUI .jar problems
Hey dlorde - Nopes, it isn't throwing an exception. The weird thing is that it adds it within Netbeans, but not when I add it using the standalone .jar.
The reason, I said that the class / libraries were fine is that I call a similar function that updates the mySQL table on another feature of the GUI and that works flawlessly. But when I try to execute this ... it doesn't add anything to mySQL.
-
July 22nd, 2009, 01:27 PM
#23
Re: GUI .jar problems
Sorry - another small problem I am facing seperate from the .jar file is that. I am trying to add a JFrame that opens up on a mouse click event within a Jtable of my GUI.
Code:
if (e.getClickCount() == 1 && column==3 && !Table.getValueAt(row, 3).toString().isEmpty() ) {
//Creating the JTable
JScrollPane getPlane = new JScrollPane();
JTable getTable = new JTable();
getPlane.add(getTable);
DefaultTableModel getTableModel = new DefaultTableModel(header, 1);
getTable.setModel(getTableModel);
//Create and set up the window.
JFrame frame1 = new JFrame();
frame1.add(getPlane);
//Display the window.
frame1.pack();
frame1.setVisible(true);
frame1.repaint();
}
With that code, I get the Frame to open up. But I've inserted some data into the table. That doesn't display , nor do the table headers. Any ideas? I can include the code that I used to fill the table but I guess that would just make it kinda messy.
EDIT : I got it to work!
Just can't figure out how to make the Jframe take the exact size of the Jtable. Any suggestions? . I don't want to manually set a preferred size, cause the table might be bigger or smaller based on the data.
Last edited by worldChanger; July 22nd, 2009 at 03:43 PM.
-
July 23rd, 2009, 12:39 AM
#24
Re: GUI .jar problems
you can predesign new frame and its contents in netbeans as new class, then simply instantiate it
-
July 23rd, 2009, 03:10 AM
#25
Re: GUI .jar problems
Just can't figure out how to make the Jframe take the exact size of the Jtable. Any suggestions?
call getSize() on the JTable object and then pass the returned value to the JFrames object's setSize() method. If you want the internal size of the JFrame to be the same size of the JTable rather than the external size, then you'll have to add the JFrames insets to the size returned by JTable.
-
July 23rd, 2009, 08:39 AM
#26
Re: GUI .jar problems
Why put the table in a scroll frame if you never want to scroll it? The scroll frame deliberately makes the size of the frame independent of the size of the table, so large tables can be displayed in smaller frames and scrolled.
If you want the frame to size itself to the table, just add the table directly the frame (or add it to a panel and add that to the frame). When you pack() the frame, it will size itself to the table.
If you want to show the table headers like a scroll pane does, you can do it like this:
Code:
...
JTableHeader header = table.getTableHeader();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(header);
panel.add(table);
frame.add(panel);
frame.pack();
frame.setVisible(true);
...
It is a bad plan that admits of no modification...
P. Syrus
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
July 23rd, 2009, 12:50 PM
#27
Re: GUI .jar problems
Hey keang - Wow, so simple. Yet so ingenius.
dlorde - I think the pack() did the trick, it displays it as I want to now. I still do have the scrollpane, I just didn't want it to become the entire size of the screen if the table was that big. The presence of the scrollpane is preventing that.
Going to get back to figuring out how to get the .jar file to work independently ...
-
July 23rd, 2009, 12:59 PM
#28
Re: GUI .jar problems
Hmm, I just realized something.
The first file that I'm trying to load into mySQL is around 2.5 mb in size. The others are smaller. So I reduced this to around 700 kb and tried the function again and it worked, this time!
This is what I concluded. All the libraries and everything are working perfectly. I'm guessing its probably just running out of memory when its trying to load the larger file? or maybe mysql cannot handle those many entries being put? But, while I build the project I assigned sufficient heap space to it I guess, I used -Xmx1024m. And with this same setting, it can add the 2.4 mb file when running the project in netbeans ...
-
July 23rd, 2009, 09:01 PM
#29
Re: GUI .jar problems
run your app insider netbeans via profiler, it is integrated with netbeans, it will tell you actual mem usage
you can see it from task manager too
-
July 24th, 2009, 09:02 AM
#30
Re: GUI .jar problems
Hey postmortem - I ran the profiler as you suggested. Initially it didn't let me run it with my specified parameter of -Xmx1024m . So, I removed this and ran the default. (I read that the default uses 1/4th of the entire system memory .. mine is 3 Gbs). The application then opened fine but as soon as I ran the feature that adds the file to mySQL, here's what I get:
Code:
init:
profile-init:
deps-jar:
compile:
profile:
Profiler Agent: Waiting for connection on port 5140, timeout 10 seconds (Protocol version: 8)
Profiler Agent: Established local connection with the tool
java.lang.OutOfMemoryError: Java heap space
Dumping heap to D:\nbproject\private\profiler\java_pid2532.hprof ...
Heap dump file created [76486386 bytes in 2.791 secs]
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at java.lang.Float.toString(Float.java:182)
at java.lang.String.valueOf(String.java:2960)
at com.mysql.jdbc.PreparedStatement.setFloat(PreparedStatement.java:3239)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|