Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to open Swing components client side  RSS feed

 
Matthew Snow
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've built a java application that allows users to save a file to their desktop using a JFileChooser in a JFrame. I've got it deployed to a Tomcat on a virtual server running CentOS (hence no monitor) so of course I'm getting a java.awt.HeadlessException when I call super(). If I run tomcat through a shell via ssh, however, it opens the file chooser on my machine which is heartening, but pointless as it doesn't matter where the application is being viewed from. How do I set this up to open swing components client side? Or, heaven forbid, must I resort to an applet?
 
Matthew Snow
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I forgot about this post. Here is what I ended up doing. I basically ditched the whole swing thing and just sent a byte stream to the HttpServletResponse object, which a browser understands as a file download. Here is the code (java 5 compliant)



The method fileEntiresToByteArray() simply parses the List object and appends the data to a String object. It then returns str.getBytes().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!