This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!

Joshua Doerring

Greenhorn
+ Follow
since Aug 08, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Joshua Doerring

modifying the above code just a little almost get me the results I need.

I tried to have the DefaultCellEditor request focus but it never occured to me to have the component it contains request focus. Also, there is still a little problem with how the TAB key reacts to this though. If I enter an incomplete value then press TAB, I still loose the focus and it does not "ding" and if I press TAB any number of times after that it does "ding". But the field is still editable and I can still enter more values.
Everything else works perfectly how I need it. Pressing up/down, left/right, clicking another row with the mouse. It all works great.
A little more FYI pressing the TAB key in this case does not call the changeSelection() method.
Thanks for all the help so far everyone. I'm going to see if I can sneek this through testing with out anyone noticing the TAB thing.
14 years ago
some one suggested this to me... override the changeSelection method of JTable

This works for the most part. Only one problem with this is inconsistant behavior. If there is an invalid value and you press down it "dings" and the caret stays where it is like it should but if you click another cell with the mouse, you get the "ding" but the caret is nolonger visible. On the same note if I start typing it append the new characters but still no caret. Kinda does the same thing if you hit the tab key, only difference here is, say I have 2 columns per row, if I hit tab once it "dings" then the caret dissappears, but if I tab a second time there is no "ding" but the caret reappears. like it tabbed to the second column then returned.
This is very strange.
Thanks for everyone's help so far.
14 years ago
A little more information I am using the above code but I changed this

instead of

other wise when you do enter a good value the box still looks like its in edit mode.
back to the point about the selected row, this only seems to be a problem with the mouse because when you hit tab or enter or left/right up/down it dings and acts like I want it to. so apparently it has to do with the mouse and how tables handle the mouse making selections
any ideas.
14 years ago
oops. wrong button. What I was going to say is that the stopCellEditing() method works great for what I'm trying to accomplish for some reason when you setCellEditor for the table instead of the individual column it doesn't work and thats what I was doing in my example.
The only thing left is when they select another row it still changes the selection to that row and the blinking cursor no longer is in the editing field but it is still editable. so I have a little more work to do on this but it is getting very close.
Thanks for the help.
14 years ago
Great the stopCellEditing
14 years ago
I did a little looking and I now know what a Spinner is. The only problem is that our company is currently restricted to using the IBM JDK 1.3.1 which is pretty much identical to Java JDK 1.3.1 but Spinner comes in 1.4 and it still wouldn't solve the problem with the fields that could contain thousands of values.
Thanks for the Spinner idea though, as soon as we start using 1.4 I'll have a few ideas of where that can be used in our current product.
14 years ago
I would like to use a JComboBox but the powers that be say they want it to be entered manually. Also, the example above would be simple enough but some of the values for other areas range in the thousands. and typing would typicall be much faster than the drop-down-and-scroll-til-you-find-it method.
And, I am not familiar with what you mean by Spinner.

For the stopCellEditing() method I have a test program I tried that with a couple of days ago and stragely enough that event was fired upon double clicking in the field and not after exiting the field and it was only fired once. double clicking and entering a new value did not retrigger the event.

In this example I was specifically checking for A01 as being the only valid value and if any thing else was entered it would "ding" and would remaing being edited.
Thanks so far for the suggestions.
14 years ago
For a particular project I'm working on the specs say that as a user types a value into a particular cell in a table, I must validate that each character is valid and that they are typing a valid code.
Example: Say valid codes are "01", "02", "10", 11", "20", ... we actually have a large number of codes and not all are numeric.
I have the part about validating as they type, if they type a 0 ... no problem so far so they type as the next character a 3 ... well there's no 03 code in the list so I make the "ding" sound and I don't even allow the 3 to show in the field. they would still see the 0 and the cursor waiting for the next char. and if they then typed 1 ... thats ok because 01 is a valid code. And in this example there are no codes larger than 2 digits so if they tryied to type any more i just make the "ding" and don't add the character.
The checking as they type works great they cannot enter a bad code... what I didn't think about is what if they just type a 1 and then exit the field. It wasn't an error because the char 1 was a valid begining to the code "11" but wasn't the complete code.
What I need to do is a second check when they're done editing the field to see if the code currently there is valid. and if it is not, do not leave the edit portion of the field and stay positioned to the last character and make the "ding" sound just as if they had typed something invalid.
For anyone's curriosity here is the TextField class that I create that columns cell editor from

Please help!
Thanks
14 years ago
The better solution is not to copy it at all. I was just having this problem in a clone method of one of our classes and it just didn't occur to me at the time when you see everything else being copied.
Thanks for the help.
14 years ago
This is the first time I noticed this but in my program I have to make an exact copy of a BigDecimal object, basically clone it. I perform the following code:
BigDecimal original = new BigDecimal("0.02");
BigDecimal copy = new BigDecimal(original.doubleValue());
System.out.println("Original: " + original);
System.out.println("Copy: " + copy);
and the following is the output:
Original: 0.02
Copy: 0.0200000000000000004163336342344337026588618755340576171875
The double gets extra numbers to the right of the decimal. Obviously this is not good. Is this a bug and is there a simple way to prevent this?
Any suggestions
Thanks
14 years ago
I wrote a java application that is launched from a command prompt on a "Windows 2000 Server."
The application simply takes data from a flat file on one server and inserts it into a table in a "SQL Server Database" on the same server the application runs on.
There are several files that get coppied this way and I wrote a class to handle each file. I have one main class that spawns the other classes as threads the following way:
...
for (int a = 0; a < programs.length; a++) {
Class program = Class.forName(programs[a]);
Object[] programArgs = new Object[6];
programArgs[0] = as400;
programArgs[1] = office;
programArgs[2] = driver;
programArgs[3] = dbURL;
programArgs[4] = user2;
programArgs[5] = password2;
Class[] programArgsClass = new Class[6];
programArgsClass[0] = programArgs[0].getClass();
programArgsClass[1] = programArgs[1].getClass();
programArgsClass[2] = programArgs[2].getClass();
programArgsClass[3] = programArgs[3].getClass();
programArgsClass[4] = programArgs[4].getClass();
programArgsClass[5] = programArgs[5].getClass();
Constructor programConstructor = program.getConstructor(programArgsClass);
Object programThread = programConstructor.newInstance(programArgs);
new Thread((Runnable) programThread, programs[a]).start();
}
...
I log output to the command prompt.
To end the program they just type CTRL-C in the command prompt or they just press the X in the upper right hand corner.
This works just fine on several customer machines. But for some reason on one of our customer machines we find the program is running on here twice. It appears only once and there is only one command prompt open. What this does is it inserts the records into the database twice. Not good.
And if the user ends the command prompt. the one you cant see is still inserting records. I went to the windows task manager and i didn't even see the java application running.
Normally when my program is running it appears as the java.exe.
There is no indication that the user is launching or ending the program any differently than the customers that are working fine.

This seems to be very strange behavior.
Any ideas?
Thanks
14 years ago
I'm using WebSphere Application Server Express 5.0 on an IBM AS/400 ISeries server. It appers that when you setup a data source in WebSphere that it automatically has connection pooling enabled for that data source. So what I do is something like the following
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
Context ctx = new InitialContext();
this.dataSource = (DataSource) ctx.lookup("jdbc/QRDataSource");
}
catch (Throwable t) {
handleException(t);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection connection = null;
try {
//...
synchronized (this.dataSource) {
connection = this.dataSource.getConnection(user, password);
}
// Deactivate commitment control
connection.setAutoCommit(true);
//...
}
catch (Throwable t) {
handleException(t);
}
finally {
if (connection != null) {
try {
connection.close();
connection = null;
}
catch (Throwable t) {
handleException(t);
}
}
}
I'm not sure if this behavior works on other webservers.
15 years ago
I see what you're getting at. Yes I do have an instance variable of type DataSource and I use it to get a connection in the getStudentInfo() and getTeacherInfo() methods. Example:
//...
Connection connection = this.dataSource.getConnection("GSDQRSHARE", "GSDQRSHARE");

// Deactivate commitment control
connection.setAutoCommit(true);
//...
So I should actually synchronize the use of this resource this this:
//...
Connection connection = null;
synchronized(this.dataSource) {
connection = this.dataSource.getConnection("GSDQRSHARE", "GSDQRSHARE");
}
// Deactivate commitment control
connection.setAutoCommit(true);
//...
Is this correct?
15 years ago
Sorry I hit the submit button by accident. I use an Applet to communicate to the servlet and the servlet looks something like this:
public class TestServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
// Receive input data
ObjectInputStream input = new ObjectInputStream(request.getInputStream());
Vector inData = (Vector) input.readObject();
input.close();
// Extract the action
String action = (String) inData.elementAt(0);
Vector outData = null;
// Perform the requested action
if (action.equalsIgnoreCase("GET_STUDENT_INFO")) {
outData = this.getStudentInfo(inData);
}
else if (action.equalsIgnoreCase("GET_TEACHER_INFO")) {
outData = this.getTeacherInfo(inData);
}
// Send output data
response.setContentType("application/x-java-serialized-object");
ObjectOutputStream output = new ObjectOutputStream(response.getOutputStream());
output.writeObject(outData);
output.flush();
output.close();
}
catch (Throwable exception) {
throw new ServletException(exception.getMessage());
}
}
private Vector getStudentInfo(Vector inData) {
Vector studentInfo = new Vector(10);
// Query Student Info
//...
return studentInfo;
}
private Vector getTeacherInfo(Vector inData) {
Vector teacherInfo = new Vector(10);
// Query Teacher Info
//...
return teacherInfo;
}
}
I know that for every call to the doPost method a new Thread is created to handle the request. But do all threads share the getStudentInfo and getTeacherInfo methods or does each thread have its own copy? I'm going to have multiple people hitting this servlet and I would not be good for performance if the methods were shared and I had to synchronize them.
Any info would be helpful.
Thanks.
15 years ago
If I do not implement SingleThreadModel and I have a servlet that looks like this:

[ Edited by Dave to add code tags ]
[ October 14, 2003: Message edited by: David O'Meara ]
15 years ago