May 26

Java provides the ZipInputStream class for reading from a zip file. Heres a general example of its usage

File file = new File("my.zip");
ZipInputStream zin = new ZipInputStream(new FileInputStream(file));
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
   String filename = ze.getName();
   if (!ze.isDirectory()) {
        // Read file contents from 'zin'
        // For example you could read from zin and write it to a FileOutputStream
        // http://helpdesk.objects.com.au/java/how-do-i-copy-one-stream-to-another-using-java
   }
   zin.closeEntry();
}
zin.close();

The same can be used to read the contents of a jar file.

written by objects \\ tags: , , , , ,

May 19

When you add a JTextField to a BoxLayout managed panel it will expand vertically to take up available space.

To avoid this you can simply set the maximum size of the field to be the same as its preferred size.

textField.setMaximumSize( textField.getPreferredSize() );

written by objects \\ tags: , ,