How would I go about creating a JTable in Swing that allows the user to toggle columns with a simple dropdown meun, like in Windows Explorer folders?
Maybe you can try JXTable
(available in SwingX library) which extends from JTable and provides such feature. This code snipet does it all:
DefaultTableModel model = new DefaultTableModel(new Object[]{"Column # 1", "Column # 2", "Column # 3","Column # 4"}, 10);
JXTable table = new JXTable(model);
table.setColumnControlVisible(true); // this added with JXTable
Screenshot
Pay attention to the top-right corner button which is responsible to display the menu: