Archive for the ‘Uncategorized’ Category
Swing – hey, that dialog looks neat, can I do it with a Password field instead?
No, it’s not as straightforward as one would hope, but after some searching around for different solutions, I settled on this one:
String user = JOptionPane.showInputDialog(null,
“Username:”,
“Enter Username”,
JOptionPane.PLAIN_MESSAGE);
Equivalent JPassword Dialog:
JPanel panel = new JPanel(new GridLayout(2, 1));
JLabel passLabel = new JLabel(“Password:”);
JPasswordField pass = new JPasswordField(20);
pass.addAncestorListener(new AncestorListener() {
public void ancestorAdded(AncestorEvent e) {
JComponent component = (JComponent) e.getComponent();
component.requestFocusInWindow();
component.removeAncestorListener(this);
}
public void ancestorMoved(AncestorEvent e) { }
public void ancestorRemoved(AncestorEvent e) { }
});
panel.add(passLabel);
panel.add(pass);
int action = JOptionPane.showConfirmDialog(null, panel, “Enter Password”, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (action == 0) {
passwd = new String(pass.getPassword());
}
Eclipse Settings – Mockito/JUnit annoyances with importing static classes
- Open Preferences (Window-> Preferences)
- Browse to Java -> Code Style -> Organize Imports
- Change ‘Number of static imports needed for .* to ‘1’
- Click Ok
OMG I can’t believe I had never found this before. No more assertTrue & assertFalse annoyances with silly static classes.