List of usage examples for java.beans PropertyChangeListener PropertyChangeListener
PropertyChangeListener
From source file:Main.java
public static void main(String[] argv) throws Exception { final JFileChooser chooser = new JFileChooser(); chooser.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY.equals(evt.getPropertyName())) { JFileChooser chooser = (JFileChooser) evt.getSource(); File oldDir = (File) evt.getOldValue(); File newDir = (File) evt.getNewValue(); File curDir = chooser.getCurrentDirectory(); }//from www. j a v a 2 s . com } }); }
From source file:Main.java
public static void main(String[] argv) { JFileChooser chooser = new JFileChooser(); chooser.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(evt.getPropertyName())) { JFileChooser chooser = (JFileChooser) evt.getSource(); File oldFile = (File) evt.getOldValue(); File newFile = (File) evt.getNewValue(); System.out.println(oldFile); System.out.println(newFile); System.out.println(chooser.getSelectedFile()); } else if (JFileChooser.SELECTED_FILES_CHANGED_PROPERTY.equals(evt.getPropertyName())) { JFileChooser chooser = (JFileChooser) evt.getSource(); File[] oldFiles = (File[]) evt.getOldValue(); File[] newFiles = (File[]) evt.getNewValue(); Arrays.toString(oldFiles); Arrays.toString(newFiles); File[] files = chooser.getSelectedFiles(); Arrays.toString(files); }//from w ww .jav a 2 s .c om } }); chooser.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { final JFileChooser chooser = new JFileChooser(); File curDir = chooser.getCurrentDirectory(); chooser.setDialogTitle("" + curDir.getAbsolutePath()); chooser.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(evt.getPropertyName())) { File curDir = chooser.getCurrentDirectory(); chooser.setDialogTitle("" + curDir.getAbsolutePath()); }/*from w ww . j a v a 2 s . c o m*/ } }); }
From source file:Main.java
public static void main(String[] args) { JProgressBar pb = new JProgressBar(0, 100); ReadFileWorker worker = new ReadFileWorker(); worker.addPropertyChangeListener(new PropertyChangeListener() { @Override//w ww .j av a 2 s . c om public void propertyChange(PropertyChangeEvent evt) { if ("progress".equalsIgnoreCase(evt.getPropertyName())) { pb.setValue(worker.getProgress()); } } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(pb); f.pack(); f.setVisible(true); worker.execute(); }
From source file:UsingFocusListener.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField("A TextField"); KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); System.out.println(prop); }/*from w w w . j a v a 2 s. com*/ }); frame.add(textField, "North"); frame.add(new JTextField(), "South"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;// w w w . j a va 2 s . c om } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } } }; tray.addPropertyChangeListener("trayIcons", pcl); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); Thread.sleep(3000); System.exit(0); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/*from w ww . ja v a2 s . co m*/ } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } } }; tray.addPropertyChangeListener("trayIcons", pcl); PropertyChangeListener[] listeners = tray.getPropertyChangeListeners("trayIcons"); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); Thread.sleep(3000); System.exit(0); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/*from w w w .j a va2 s. c om*/ } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } } }; tray.addPropertyChangeListener("trayIcons", pcl); Dimension size = tray.getTrayIconSize(); TrayIcon[] icons = tray.getTrayIcons(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); Thread.sleep(3000); System.exit(0); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/*from w w w. ja va 2 s .c o m*/ } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } } }; tray.addPropertyChangeListener("trayIcons", pcl); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); tray.removePropertyChangeListener("trayIcons", pcl); Thread.sleep(3000); System.exit(0); }
From source file:SystemTrayDemo1.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;//w ww . ja va 2 s. co m } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { System.out.println("Old tray icon array contents: "); for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); System.out.println(); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { System.out.println("New tray icon array contents: "); for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); System.out.println(); } } }; tray.addPropertyChangeListener("trayIcons", pcl); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); g.setColor(Color.yellow); int ovalSize = (size.width < size.height) ? size.width : size.height; ovalSize /= 2; g.fillOval(size.width / 4, size.height / 4, ovalSize, ovalSize); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); Thread.sleep(3000); System.exit(0); }