how to use a swing timer to start/stop animation

import javax.swing.Timer; Add an attribute; Timer timer; boolean b; // for starting and stoping animation Add the following code to frame’s constructor. timer = new Timer(100, new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { // change polygon data // … repaint(); } }); Override paint(Graphics g) and draw polygon from the data that was … Read more

How to gray-out non-editable cell in jtable?

Return an instance of GrayableCheckboxCellRenderer in a TableCellEditor. Addendum: Aesthetically, you may want to condition the renderer’s and editor’s colors based on the defaults provided by the current Look & Feel, for example: Color hilite = UIManager.getColor(“Table.selectionBackground”);

how to add checkbox and combobox in table cell?

Here is combo cell insets replicate demo: import java.awt.*; import java.awt.event.*; import java.util.EventObject; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; public class ComboCellInsetsDemo { public JComponent makeUI() { String[] columnNames = {“Name”, “Check”, “Condition”}; Object[][] data = { {“bbb”, false, “=”}, {“aaa”, true, “<“} }; DefaultTableModel model = new DefaultTableModel(data, columnNames) { @Override public Class<?> getColumnClass(int … Read more

jScrollPane can’t add component

You’re mixing heavy weight (AWT) components with light weight (Swing) components, this is inadvisable as they don’t tend to play well together. JScrollPane contains a JViewPort onto which you can add a child component, AKA the view. (image from the JavaDocs) So the call jScrollPane.getViewport().setLayout(new FlowLayout(FlowLayout.CENTER)); is actually setting the JViewPort‘s layout manager, which really … Read more

How to avoid firing actionlistener event of JComboBox when an item is get added into it dynamically in java?

You could remove the action listener before you add the new elements, and add it back once you’re done . Swing is single threaded so there is no need to worry about other threads needing to fire the listener. Your listener could probably also check if something is selected and take appropriate action if not. … Read more