Different tooltip for each word in JTextField

It is possible to set a tooltip for a JTextField no doubt. It’s also possible to set a tooltip based on what you have typed directly, like:
private JTextField searchTxt = new JTextField(20);
private final Document searchTxtDoc;
..
searchTxtDoc = searchTxt.getDocument();
searchTxtDoc.addDocumentListener(new searchTxtListener());
..
private class searchTxtListener implements DocumentListener {
  public void changedUpdate(DocumentEvent de) { checkTxtContent(); }
  public void insertUpdate(DocumentEvent de) { checkTxtContent(); }
  public void removeUpdate(DocumentEvent de) { checkTxtContent(); }
};

In checkTxtContent(); it’s possible to do what’s necessary with the JTextField content and set a tooltip. In fact, I use this listener often to present more information.

But what if it’s required to set tooltips on the JTextField based on every single word typed. Maybe the mouse position is useful to show a tooltip along the word the mouse is hoovering. Is it possible to gather the mouse information in checkTxtContent(); but it’s not the proper event to catch from the DocumentListener since it is fired on a document event.

In a GUI everything is event driven, so a good way to catch the mouse is using a MouseAdapter and add a MouseListener to the JTextField: searchTxt.addMouseListener(new searchMouseListener());
and:
private class searchMouseListener() extends MouseAdapter {
  public void mouseClicked(MouseEvent me) {
    // e.g. if right mouse button clicked (or me.isPopupTrigger())
    if(SwingUtilities.isRightMouseButton(me)) {
      
    }
    // e.g. show popup
    menuItem.show(JComponent, me.getX(), me.getY());
  }
}

With this MouseEvent it is possible to use me.getPoint(); or me.getX(); and me.getY();

But… The methods available are: mouseClicked, mouseEntered, mouseExited, mousePressed and mouseReleased. mouseEntered and mouseExited only deliver coordinates at one moment (their name says it all), not continuously.

So… not sufficient, best way to catch the mouse position is to use the MouseMotionListener. This class provides the following two methods: mouseDragged and mouseMoved. The latter is just what we needed:
searchTxt.addMouseMotionListener(new searchMouseMotionListener());

and

private class searchMouseMotionListener implements MouseMotionListener {
  public void mouseDragged(MouseEvent mouseEvent) {}
  public void mouseMoved(MouseEvent me) {
    String wrd = "";
    String txt = searchTxt.getText();
    int end = txt.length();
    if(end>0) {
      int pos = searchTxt.viewToModel(me.getPoint());
      if(pos>=0) {
        StringTokenizer st = new StringTokenizer(txt);
        int cur_pos = 1;
        while(st.hasMoreTokens()) {
          wrd = st.nextToken();
          cur_pos = cur_pos + wrd.length() + 1;
          if(cur_pos>=(pos+2)) {
            // wrd contains the word we're looking for,
            // so create a tooltip based on this catch
            break;
          }
        }
      }
    } // implement other stuff in else branches
  }
}

Hope it works for you.

Java zip, miracles do happen

From June 1999 we were waiting…
See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4244499 to process zips from inside Java.

Note: quote ‘Miracles happen’ is from Martin Hilpert

And finally, unzippin’ bizarre character filenames in java se7, jdk7, jee1.7 or do we call it just java7 , is there.

Oracle owns Java now (well, Sun before) and runs a JVM inside, unfortunately I don’t think this bugfix will be available within the Oracle database JVM soon (or at all). More on that later!

php upload_max_filesize when uploading images

After installing a new server, I got the upload_max_filesize message from WordPress (from php) after I tried to upload a large image file:

Of course I forgot to edit the /etc/php5/apache2/php.ini file at line 877:

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 2M

Just 2Mb is not much… Can be altered though!

VNC on openSUSE 11 was 10.3

As some other colleagues, I ran into some trouble upgrading from openSuse 10.3 to openSuse 11 when using VNC.

My server is located in a data-center, so I usually use ssh to logon. In rare occasions I want to graphically take control (when it’s time for a new kernel). And from openSuse 11 this isn’t that simple anymore.

Lot’s of Google hits on this problem, but it depends on your configuration. I’ve got 2. First:
-edit /etc/xinetd.d/vnc and set depth to 32 bits
-remove any IPv6 reference in your /etc/hosts file

But I know for sure that I’ve accomplished something else when I created my first openSuse 11 (vmware) installation way-back in 2009. I’ve forgotten how I’ve managed that one, but it still has its IPv6 references. So, I’ll get back on that one!

For now, my new (fallback) host is configured for remote access. I’ll get back in touch when I’ve discovered the other solution.

Print stylesheet for zoom

While Opera, Firefox and Safari print html pages very nice and have shrink to fit features, IE often seems to corrupt the margins.

A reminder to myself, use in header part:

<style type="text/css" media="print">
  body { zoom: .65; }
</style>

The zoom property is only used by IE.