actionlistener

Updating swing components within edt

独自空忆成欢 提交于 2020-06-29 18:49:56
问题 If I understand correctly then when I create GUI swing components, for example I have this: public class frameExample extends JFrame{ public frameExample(){ //Here adding bunch if components setVisible(true); } } So as long as I don't call the setVisible method the components are being made from the thread the instance was created. So if in a class where i have my main method write: JFrame test=new frameExample(); and I sysout Thread.currentThread.getName(); in the constructor in frameExample

JTable - Checkbox add action listener

回眸只為那壹抹淺笑 提交于 2020-05-27 11:49:06
问题 I've created a simple JTable with check box like below: DefaultTableModel model = new DefaultTableModel(); jTable1.setModel(model); model.addColumn("No:", no1); model.addColumn("Remark", remark1); model.addColumn("Color", colors1); model.addColumn("Done"); TableColumn col1 = jTable1.getColumnModel().getColumn(0); col1.setPreferredWidth(1); TableColumn col4 = jTable1.getColumnModel().getColumn(3); col4.setCellEditor(jTable1.getDefaultEditor(Boolean.class)); col4.setCellRenderer(jTable1

JTable - Checkbox add action listener

≯℡__Kan透↙ 提交于 2020-05-27 11:49:04
问题 I've created a simple JTable with check box like below: DefaultTableModel model = new DefaultTableModel(); jTable1.setModel(model); model.addColumn("No:", no1); model.addColumn("Remark", remark1); model.addColumn("Color", colors1); model.addColumn("Done"); TableColumn col1 = jTable1.getColumnModel().getColumn(0); col1.setPreferredWidth(1); TableColumn col4 = jTable1.getColumnModel().getColumn(3); col4.setCellEditor(jTable1.getDefaultEditor(Boolean.class)); col4.setCellRenderer(jTable1

Class “is not abstract and does not override abstract method” error

与世无争的帅哥 提交于 2020-03-28 07:04:33
问题 I am following a Java tutorial at https://youtu.be/64V8CC7nSok. I have copied the code 100% from the video, but still I get this error: Board is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener I have already searched for similar cases, but it didn't help. Here is the file with the error, Board.java , which is sufficient to reproduce the problem: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Board extends JPanel

ActionListener and Thread.sleep

风格不统一 提交于 2020-03-12 05:44:46
问题 I have a JButton, which, as soon as I click on it, I want to change some colors after a few seconds, for example from blue -> 1 sec -> red -> 1 sec -> yellow. My problem is that, as soon as I use the Thread.sleep function in ActionListener and I test my program, it freezes for the 2 seconds and gives me directly yellow. How can I fix that? Thanks a lot 回答1: ActionListener and Thread.sleep.. ..don't play well together. Don't block the EDT (Event Dispatch Thread) - the GUI will 'freeze' when

ActionListener and Thread.sleep

ぐ巨炮叔叔 提交于 2020-03-12 05:44:27
问题 I have a JButton, which, as soon as I click on it, I want to change some colors after a few seconds, for example from blue -> 1 sec -> red -> 1 sec -> yellow. My problem is that, as soon as I use the Thread.sleep function in ActionListener and I test my program, it freezes for the 2 seconds and gives me directly yellow. How can I fix that? Thanks a lot 回答1: ActionListener and Thread.sleep.. ..don't play well together. Don't block the EDT (Event Dispatch Thread) - the GUI will 'freeze' when

How to assign a sepecifc action to the (“Cancel”) button within (JOptionPane.showInputDialog) in Java?

≡放荡痞女 提交于 2020-02-05 06:02:07
问题 Here is my question with a short sample code: double num = 0.00; try { num = Double.parseDouble(JOptionPane.showInputDialog("Enter your num:")); } catch (Exception e) { System.err.println("Error: Invalid Input!"); JOptionPane.showMessageDialog(null, "Error: Invalid Input!", "Error", JOptionPane.ERROR_MESSAGE); } //Validate the num if (num > 0.0 && num <= 1000.00) { functionA(); } else if (deposit <= 0.0 || deposit > 1000.00) { System.err.println("Error: out of range"); } *The Problem with the

JButton background image

假如想象 提交于 2020-01-31 05:39:11
问题 Hi i am trying to implement Action listener for JButton and code look like following: ImageIcon imageForOne = new ImageIcon(getClass().getResource("resources//one.png")); one = new JButton("",imageForOne); one.setPreferredSize( new Dimension(78, 76)); one.addActionListener(myButtonHandler); Using the above JButton it looks fine When i add specific value to button for e.g. ImageIcon imageForOne = new ImageIcon(getClass().getResource("resources//one.png")); //Check this one = new JButton("one"