Posts

Showing posts with the label java

Quick way to disable table header in JTable

Last week was Java week. It involved quickly adding a new tab to an existing Java applet application. The layout has a nice larger table header section and allows for the table itself to have a sub-header. That is pretty slick. Until you don't need a sub-header :). After a bit of searching I found a pretty Perl-ish way to disable table headers in Java's JTable. myTable.setTableHeader(null); I kept looking for a disableTableHeader method. This week its off to Excel, Web Posts and VBA again... yikes.

Setting Java Socket Timeouts

Oddly, Java's Socket library doesn't allow you to set the socket timeout directly in the constructor. Its important to note that there is no default so the socket will last forever (ish). Note: The socket timeouts below apply to different situations: setSoTimeout applies to read timeouts. connect applies to connection establishment. At least that's how I read it. I found two options, setting the option on the socket after creating one simplest (for me at least): Socket s; try { s = new Socket( ip, port ); s.setSoTimeout( secs * 1000 ); // converts secs to ms // do other stuff like get input stream and read it } catch ( SocketException se ) { // catch timeout or other socket related error } catch ( Exception e ) { // any other exception } The other option is creating a Socket object without any parameters then calling the connect method with timeout. Here is a rough prototype since it seemed like pain to me but I was curious about the code: Socket s = new Socket...

JBuilder 8 losing Libraries

After not running JBuilder 8 for a bit, when I tried to rebuild an applet at $work, I received a very strange set of missing class errors. These classes were right there in the Jar libraries... I swear :) Well after a few hours of looking around I found that I need to remove the whole 'output path' option (under Run -> Configurations -> Path tab). Then it magically worked. Go Figure. I know JBuilder8 is ancient but one applet builds in it and nobody wants to fund it moving to Eclipse...