Why JScrollPane does not react to mouse wheel events?

Walter beat me to analysing the issue 🙂 Adding a bit of detail: It’s correct that a JScrollPane supports mouseWheelHandling. According to the rules of mouseEvent dispatching, the top-most (in z-order) component gets the event, and that’s the scrollPane around the textArea. So if wheeling the textarea is not required, a simple solution might be … Read more

Java Swing Timer

This simple program works for me: import java.awt.event.*; import javax.swing.*; public class Test { public static void main(String [] args) throws Exception{ ActionListener taskPerformer = new ActionListener() { public void actionPerformed(ActionEvent evt) { //…Perform a task… System.out.println(“Reading SMTP Info.”); } }; Timer timer = new Timer(100 ,taskPerformer); timer.setRepeats(false); timer.start(); Thread.sleep(5000); } }

JOptionPane to get password

Yes, it is possible using JOptionPane.showOptionDialog(). Something like this: JPanel panel = new JPanel(); JLabel label = new JLabel(“Enter a password:”); JPasswordField pass = new JPasswordField(10); panel.add(label); panel.add(pass); String[] options = new String[]{“OK”, “Cancel”}; int option = JOptionPane.showOptionDialog(null, panel, “The title”, JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if(option == 0) // pressing OK button { char[] … Read more

how to print selected rows JTable

Seems to work okay for me… import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.PrinterException; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; public class TestPrint { public static void main(String[] args) { new TestPrint(); } public TestPrint() { EventQueue.invokeLater(new … Read more

Disable multiple date ranges jDateChooser

Based on your update there are two things that happen here. First is a little mistake when you instatiate your SimpleDateFormat: SimpleDateFormat dateFormat = new SimpleDateFormat(“dd-mm-yyyy”); In this pattern “mm” refers to minutes not months. It should be: SimpleDateFormat dateFormat = new SimpleDateFormat(“dd-MM-yyyy”); Second problem is IMHO a bug since day chooser seems to not … Read more

Best way for automatic databinding between database and user interface in java swing app?

This is a complex topic that might make a good Community Wiki. I’ve only scratched the surface, but NetBeans has an evolving capability in this area. It should be on your short list. See these help topics & links: Generating JPA Controller Classes from Entity Classes Binding Data to a Swing Component Java Persistence Tasks: … Read more