• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

My Swing JTable won't work!

 
Eelco den Heijer
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, currently I'm more or less in the last phase of the Developer exam. Most stuff was pretty straightforward, except for the Swing part. Never used Swing before, and can't say I will after the exam :-)
Anyways, I have the 'Fly by Night' stuff, and have to implement the search-using-criteria. The backend stuff is all there; when I search for all flights going from SFO to DEN, I print them to std. err. and it's all fine. Except: the bloody JTable won't update. It just displays an empty line (I made the background yellow, so I at least know that there is an empty line). I did the entire thing with a dummy data model consisting of 4 arrays of strings: this works fine....
Any pointers? Please, this stupid Swing stuff is driving me nuts!!
Bye,
Eelco
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you creating a class that extends the DefaultTableModel.
Have you tried going to sun's tutorial on Swing?
Here is the start of the Trail:
http://java.sun.com/docs/books/tutorial/uiswing/index.html
Even though you might not use Swing at another time, there are some great things to learn from it, like how to use Model-View-Controller design Pattern, and the Event/Listener Patterns. I really suggest taking the time to learn about Swing, rather than trying to get the assignment submitted as soon as possible.
You will be very thankful later on.
Oh, by any chance is your last name Ono? They have a policy at Javaranch where they want you to register with your first and last name, no handles. You would have to re-register afresh.
Mark
[ January 17, 2002: Message edited by: Mark Spritzler ]
 
Eelco den Heijer
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
Thanks for the feedback.
1. Yes, I implemented the TableModel as a subclass of the DefaultTableModel.
2. Yes, I did the Swing tutorial, but the section on JTable's is a bit short.
I agree, the MVC design pattern is very useful,
but Swing is not the sole implementor of the
pattern. There are some advantages of Swing,
but I think there are many disadvantages too
(it's pretty slow, it can get rather complex,
nobody uses it).
For the SCJD exam, I would personally skip
the silly 'make-your-own-database' nonsense,
and use JDBC like the rest of the world.
Next, I would let people choose between AWT
and Swing. I'm pretty good at AWT (especially
applets). Think of it: how often did you use
a Swing client, and how often did you use
an AWT applet? Sun can dictate what they want
people to learn about Java (Swing for example)
but it doesn't mean the market will follow.
Enfin, just my 2 Eurocents.
By the way, Yoko is not my real name
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually Universal/MCA Films use Swing in a cool application, and Here at my work we were going to use Swing for our business applications. The only problem we had was that Java cannot print reports.
As far as the speed of Swing, we had not problems. I think they have to get Swing onto business computers.
The biggest frustration that we had here was that everyone assumes that if you use Java you are using the Web and HTML. But for real business applications there is no Web or HTML that can handle the complexity of screens and logic.

I had a method called assingJTable, I passed the criteria string to it, which is called the criteriaFind method in the Data class. I passed the DataInfo[] array to a new FlightTableModel() constructor, which creates the table model from the data, and then called setModel on the JTable.
Hope that is clear
Mark
 
Eelco den Heijer
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
Thanks for the feedback. Your example of the use of the DataModel made me realize that the bug was probably no in the Swing JTable, but in my use of the DataModel. Indeed, instead of re-creating the DataModel, I re-used the same one over and over. A quick fix was enough to get everything working, so now I'm really close to submitting everything.
Thanks a lot!
Eelco
BTW: about our Swing discussion; there is an interesting and provocative article on JavaLobby on the same topic: Swing article
 
Tim Holloway
Saloon Keeper
Posts: 18359
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,
Java can handle printing in several ways. However, they're generally not the same ways as you would in a standalone or client/server environment.
If you DO run standalone Java apps, there's a set of Java printing classes. They can also be used by applets if they're signed. Unsigned applets are forbidden to use it.
For "I-want-the-data-and-I-don't-care-how-it-looks" printing, you can have a server-side application build up an HTML or text file (or, if you prefer, MS-WORD, Excel, etc. document). The user does have to issue the actual command to print it, for security purposes (you can put a "Print" button on the page in some browsers - otherwise it's menu File/Print).
Then there's the "It's-gotta-look-exactly-right" kind of print. Most commonly this is done by outputting a PDF document. I use an open-source package named gnujpdf (formerly retepPdf) which behaves a lot like the Java printing classes do. There are also some commercial packages for building PDF's as well.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim,
actually we are the "it has to look exactly right, and it needs to be a banded report to be able to handle our complex reports". I have found for our reports, that even VB and Crystal Reports has a very difficult time making these reports. Whereas in Foxpro, they were a piece of cake, so to speak.
the banded report writers for Java took at least 3 minutes to render one of our simple reports. Most took 10 minutes. The users would kill us if they had to wait that long, especially when they have had those reports in less than 1 second in Foxpro.
Now, don't think I have a (Sexual Reference here) for Foxpro. I used to be a Foxpro programmer, but not anymore. I use Java, VB, VB.net, and Oracle for my applications now.
And as far as the Print classes, they are so basic
that they can't handle our printing requirements. As far as classes making PDF's we could have also used XML with XSL to transform the data into PDF or any other source, but the learning curve for us was too high, and we needed something quick.
It is a bummer that we won't use Java here again, but We are a business that needs to move forward now, and can't wait for the technology to work itself out.
Mark
 
Tim Holloway
Saloon Keeper
Posts: 18359
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's less a case of the technology not being there than that there's a lot of stuff out there and people still don't know what to tap into.
Last year I had to do some "exactly right" reports and got much better throughput than that, but the trick there was in part because I let Java do what Java did best and other subsystems do what they did best. I was adapting a legacy system (*DOS* legacy, no less) to print reports via the Internet. The reports themselves were mainframe-style. That is, no graphics, no special fonts, nothing, Just line after line of printed text. They were generated by a backend C program that printed them out to a file. The webserver then picked the text lines out, and PDF'd them on the fly using gnujpdf. Total time from the computational kickoff until the PDF showed up in the user's browser was about 15 seconds for about 200 pages of output (this was on a LAN connection, so the line speed bottleneck was minimal).
You can say that I cheated because the calculations were in Java and I'd agree except that I too had real-world project constraints, and one of them was not to re-invent stuff that was already debugged. Although JIT compilers or not, I'm afraid that I still would go for C if raw computation speed was at stake. Or at least use a Java compiled that produced optimized native code instead of bytecodes.
I'm not sure I understand about the print classes being too basic to be used. They map the display functionality, and pretty much anything you can display in Windows can be created in Java.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They map the display functionality, and pretty much anything you can display in Windows can be created in Java.

Exactly, what we were printed was not the screen. But a reoprt, that was built before in Foxpro 2.6, so We couldn't use the old stuff, and the reports had lots of "Graphics" lines, and such that only a "Windows" app could do. And the last thing we couldn't do was have it have to go through hoops/hacks to get it to work. Our knowledge and time did not allow us to go this far.
Thanks
Mark
 
Tim Holloway
Saloon Keeper
Posts: 18359
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since we've gotten off-topic, I created a new thread here: http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=003588
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic