How to validate a JTextField?

Any validation in Swing can be performed using an InputVerifier. 1. First create your own input verifier: public class MyInputVerifier extends InputVerifier { @Override public boolean verify(JComponent input) { String text = ((JTextField) input).getText(); try { BigDecimal value = new BigDecimal(text); return (value.scale() <= Math.abs(4)); } catch (NumberFormatException e) { return false; } } } … Read more

In Java Swing how do you get a Win32 window handle (hwnd) reference to a window?

You don’t have write any C/JNI code. From Java: import; public static long getHWnd(Frame f) { return f.getPeer() != null ? ((WComponentPeer) f.getPeer()).getHWnd() : 0; } Caveats: This uses a sun.* package. Obviously this is not public API. But it is unlikely to change (and I think less likely to break than the solutions … Read more

How to wrap lines in a jtable cell?

The problem is that the height of rows in JTable is fixed, so it’s not just a matter of having a renderer that wraps; I’m not sure why it doesn’t, but if it did, the wrapped text would be cropped – or maybe that’s exactly what you’re seeing. To adjust row heights, you need to … Read more