projectList.addPropertyChangeListener(JProjectList.SELECTED, todoList);
projectList.addPropertyChangeListener(JProjectList.SELECTED, activityList);应该是这两句
具体实现应该在todoList和activityList中好像涉及到bean了,用于动态刷新swing,有再完整点的代码么,学习学习

解决方案 »

  1.   

    febchen() ,你好!我感觉不是这两句吧,这两句好像是根据projectList列表里的project的状态的变化而在todoList和activityList添加相关属性吧?!我指的是在projectList列表里双击其中的一个创建好的project后,再跳出一个JFrame编辑框,而不是转移到下面的两个todoList和activityList列表里(这两个列表和projectList列表在同一个JFrame框的呀)。但我又找不出双击projectList列表里的某个project后,到底是执行哪几句话才跳出一个新的JFrame编辑框???跟上面代码你说的这两句相关的函数如下://projectList.addPropertyChangeListener的addPropertyChangeListener方法的代码如下:public synchronized void addPropertyChangeListener(
    String propertyName,
    PropertyChangeListener listener) {
    if (listener == null) {
        return;
    }
    if (changeSupport == null) {
        changeSupport = new SwingPropertyChangeSupport(this);
    }
    changeSupport.addPropertyChangeListener(propertyName, listener);
        }
    ---------------------------------------changeSupport.addPropertyChangeListener的addPropertyChangeListener方法如下:public synchronized void addPropertyChangeListener(
    String propertyName,
    PropertyChangeListener listener) {
    if (children == null) {
        children = new java.util.Hashtable();
    }
    SwingPropertyChangeSupport child =
                (SwingPropertyChangeSupport)children.get(propertyName);
    if (child == null) {
        child = new SwingPropertyChangeSupport(source);
        children.put(propertyName, child);
    }
    child.addPropertyChangeListener(listener);
        }
    ---------------------------------------child.addPropertyChangeListener的addPropertyChangeListener方法如下:public synchronized void addPropertyChangeListener(
    PropertyChangeListener listener) {
            if (listener instanceof PropertyChangeListenerProxy) {
                PropertyChangeListenerProxy proxy =
                        (PropertyChangeListenerProxy)listener;
                // Call two argument add method.
                addPropertyChangeListener(proxy.getPropertyName(),
                        (PropertyChangeListener)proxy.getListener());
            } else {
                if (listeners == null) {
                    listeners = new EventListenerList();
        }
                listeners.add(PropertyChangeListener.class, listener);
            }
        }
    -------------------------------------
    listeners.add的add方法如下:public synchronized void add(Class t, EventListener l) {
    if (l==null) {
        // In an ideal world, we would do an assertion here
        // to help developers know they are probably doing
        // something wrong
        return;
    }
    if (!t.isInstance(l)) {
        throw new IllegalArgumentException("Listener " + l +
     " is not of type " + t);
    }
    if (listenerList == NULL_ARRAY) {
        // if this is the first listener added, 
        // initialize the lists
        listenerList = new Object[] { t, l };
    } else {
        // Otherwise copy the array and add the new listener
        int i = listenerList.length;
        Object[] tmp = new Object[i+2];
        System.arraycopy(listenerList, 0, tmp, 0, i);     tmp[i] = t;
        tmp[i+1] = l;     listenerList = tmp;
    }
        }
      

  2.   

    好像这段话是显示用户在projectList里创建的project吧:
    Collection allProjects = soapclient.getProjects();
    Iterator i = allProjects.iterator();
    while (i.hasNext())
    {
    String name = (String) i.next();
    subscription = subscription + " projectName = '" + name + "' OR";
    if (!name.matches(".*_instance.*"))
    this.projects.add(name);
    }
    -----------------------
    但接下来是哪里体现双击其中一个project,产生一个新的编辑框呢?
    另外,febchen()说的“好像涉及到bean了,用于动态刷新swing”怎么看的?
      

  3.   

    实现的地方应该不在你贴出的代码里,你的list类不一定是List,可能是继承了JList或者JTable的子类,其中都可以通过setCellRenderer来控制表现方式,如果是JTable更可以通过setDefaultCellEditor控制不同类的编写方式,如果是我,也会这么做,但尽量不继承。
      

  4.   

    不是这里体现那该是哪里体现呢?这个buileView()所在.java文件全部代码如下:
    --------------------------------------
    public class Manager extends JPanel { static java.util.ResourceBundle resource = java.util.ResourceBundle.getBundle("resources.Traduction")/*#BundleType=List*/; String url = null, host = null;
    int port; 
    String userName = null;
    String userPassword = null;
    Collection projects = new ArrayList();
    JProjectList projectList = null;
    final JFrame p = new JFrame();
    BonitaClient soapclient;
    public final static String imageBase = "images/";
    public final static ImageIcon icon = new ImageIcon(Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png")); public Manager(String userName, String userPassword) throws Exception { this.userName = userName;
    this.userPassword = userPassword;
      
            // Obtains bonita host and port
    url = System.getProperty("bonita.host");     host = url.substring(7);
    int point = host.indexOf(":");
    url = host;
    this.host = host.substring(0,point);
    int portPoint = url.indexOf("/");
    if (portPoint != -1) 
    this.port = new Integer(url.substring(point+1,portPoint)).intValue(); // ant application
    else
    this.port = new Integer(url.substring(point+1)).intValue(); //Java Web Start application BonitaClient soapclient = new BonitaClient(host, port, "/bonita_ws/services/");
    soapclient.login(userName, userPassword);
    this.soapclient = soapclient;
    buildView();
    } public void buildView() throws Exception {
    String subscription = "(event = 'addUserProject' AND userName = '" + this.userName + "')" + " OR"; Collection allProjects = soapclient.getProjects();
    Iterator i = allProjects.iterator();
    while (i.hasNext())
    {
    String name = (String) i.next();
    subscription = subscription + " projectName = '" + name + "' OR";
    if (!name.matches(".*_instance.*"))
    this.projects.add(name);
    } MListener ml = MListener.getInstance(this.userName, this.userPassword, this.host, this.port);
    ml.subscription(subscription.substring(0, subscription.length() - 3));
    projectList = new JProjectList(this.soapclient, ml, this.projects);
    projectList.setBackground(new Color(177,177,251));
    JTodoList todoList = new JTodoList(this.soapclient, ml);
    todoList.setBackground(new Color(177,177,251));
    JActivityList activityList = new JActivityList(this.soapclient, ml);
    activityList.setBackground(new Color(177,177,251)); projectList.addPropertyChangeListener(JProjectList.SELECTED, todoList);
    projectList.addPropertyChangeListener(JProjectList.SELECTED, activityList); java.net.URL iconUrl = Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png");
    p.setIconImage(Toolkit.getDefaultToolkit().getImage(iconUrl)); hero.client.manager.Menubar menubar = new hero.client.manager.Menubar(this);
    menubar.setBackground(new Color(153, 153, 255));
    p.setJMenuBar(menubar);
    Container c = p.getContentPane();
    c.setLayout(new GridLayout(3, 1));
    c.add(projectList);
    c.add(todoList);
    c.add(activityList); p.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    try {
    JMSServicesClient jms = JMSServicesClient.getInstance();
    jms.closeConnection();
    System.exit(0);
    } catch (Exception ex) {
    }
    }
    }); p.setSize(new Dimension(150, 400)); p.setTitle(resource.getString("manager.activity") + userName);
    p.pack();
    p.show();
    }
      

  5.   

    public void CloneProject() {
    JPanel jp = new JPanel(); Object[] possibleValues = this.projects.toArray();
    JComboBox projectNames = new JComboBox(possibleValues);
    jp.setLayout(new GridLayout(0, 2));
    jp.add(new JLabel(resource.getString("manager.choose"), SwingConstants.LEFT));
    jp.add(projectNames); JTextField newProject = new JTextField("", 0);
    jp.setLayout(new GridLayout(0, 2));
    jp.add(new JLabel(resource.getString("manager.create.name2"), SwingConstants.LEFT));
    jp.add(newProject); int cloneOption = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.create.clone"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon);
    if (cloneOption != JOptionPane.CANCEL_OPTION) {
    while ((newProject.getText()).equals("") && cloneOption != JOptionPane.CANCEL_OPTION) {
    JOptionPane.showMessageDialog(null,resource.getString("manager.create.name"),resource.getString("manager.create.clone"),JOptionPane.INFORMATION_MESSAGE,icon);
    cloneOption = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.create.clone"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon);
    }
    if (cloneOption != JOptionPane.CANCEL_OPTION) {
    try {
    if (exists(newProject.getText())) {
    JOptionPane.showMessageDialog(null,resource.getString("manager.create.exist"),resource.getString("manager.create.clone"),JOptionPane.INFORMATION_MESSAGE,icon);
    } else{
    soapclient.cloneProject((String) projectNames.getSelectedItem(), newProject.getText());
    this.projects.clear();
    Collection allProjects = soapclient.getProjects();
    Iterator i = allProjects.iterator();
    while (i.hasNext())
    {
    String name = (String) i.next();
    if (!name.matches(".*_instance.*"))
    this.projects.add(name);
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    JOptionPane.showMessageDialog(null,resource.getString("manager.create.exist"),resource.getString("manager.create.clone"),JOptionPane.INFORMATION_MESSAGE,icon);
    }
    }
    }
    }

    public void InstantiateProject() {
    JPanel jp = new JPanel(); Object[] possibleValues = this.projects.toArray();
    JComboBox projectNames = new JComboBox(possibleValues);
    jp.setLayout(new GridLayout(0, 2));
    jp.add(new JLabel(resource.getString("manager.choose"), SwingConstants.LEFT));
    jp.add(projectNames); int instOption = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.create.inst"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon);
    if (instOption != JOptionPane.CANCEL_OPTION) {
      try {
    soapclient.instantiateProject((String) projectNames.getSelectedItem());
    this.projects.clear();
    Collection allProjects = soapclient.getProjects();
    Iterator i = allProjects.iterator();
    while (i.hasNext())
    {
    String name = (String) i.next();
    if (!name.matches(".*_instance.*"))
    this.projects.add(name);
    }
      } catch (Exception e) {
    e.printStackTrace();
    JOptionPane.showMessageDialog(null,resource.getString("manager.inst.error")+", "+e.getMessage(),resource.getString("manager.create.inst"),JOptionPane.INFORMATION_MESSAGE,icon);
      }
    }
    } private boolean exists(String project) {
    try {
    Object[] elems = this.projects.toArray();
    for (int i = 0; i < elems.length; i++) {
    if (((String) elems[i]).equalsIgnoreCase(project))
    return true;
    }
    return false;
    } catch (Exception e) {
    e.printStackTrace();
    }
    return true;
    } public void NewProject() {
    projectList.newProject();
    }


    static public void main(String[] args) {
    boolean exit = false;
    String userName = null;
    String userPassword = null; if (System.getProperty("user.login") != null && System.getProperty("user.password") != null) {
    try {
    userName = System.getProperty("user.login");
    char[] password = System.getProperty("user.password").toCharArray();
    userPassword = new String(password);
    new Manager(userName, userPassword);
    } catch (Exception e) {
    JOptionPane.showMessageDialog(null,resource.getString("manager.login.failed"),resource.getString("manager.login.login"),JOptionPane.INFORMATION_MESSAGE,icon);
    System.exit(0);
    }
    } else {
    while (!exit) {
    JPanel jp = new JPanel(); JTextField login = new JTextField("", 0);
    jp.setLayout(new GridLayout(0, 2));
    jp.add(new JLabel(resource.getString("manager.login.login"), SwingConstants.LEFT));
    jp.add(login); JPasswordField passwd = new JPasswordField("", 0);
    jp.setLayout(new GridLayout(0, 2));
    jp.add(new JLabel(resource.getString("manager.login.password"), SwingConstants.LEFT));
    jp.add(passwd); try {
    if (System.getProperty("user.login") != null && System.getProperty("user.password") != null) {
    userName = System.getProperty("user.login");
    char[] password = System.getProperty("user.password").toCharArray();
    userPassword = new String(password);
    new Manager(userName, userPassword);
    exit = true;
    } else { int option = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.login"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,icon);
    if (option != JOptionPane.CANCEL_OPTION) {
    while (((login.getText()).equals("") || (passwd.getPassword()).length == 0) && option != JOptionPane.CANCEL_OPTION) {
    JOptionPane.showMessageDialog(null,null,resource.getString("manager.login.relogin"),JOptionPane.QUESTION_MESSAGE,icon);
    option = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.login"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon);
    }
    if (option != JOptionPane.CANCEL_OPTION) {
    userName = (String) login.getText();
    char[] password = passwd.getPassword();
    userPassword = new String(password);
    new Manager(userName, userPassword);
    exit = true;
    } else
    System.exit(0);
    } else
    System.exit(0);
    }
    } catch (Exception e) {
    JOptionPane.showMessageDialog(null,resource.getString("manager.login.failed"),resource.getString("manager.login.login"),JOptionPane.QUESTION_MESSAGE,icon);
    exit = false;
    }
    }
    }
    }
    }
    ---------------------------------
    哪位帮我指一下是哪里执行“双击”动作呢???bow!!!
      

  6.   

    不是这里实现就是在projectList,todoList等具体写好了Render和Editor的类中实现,正如我上面所说的,SWING的这些组件可以通过上面所说的相关方法设置表现(Render)和修改(Editor)的方式来实现,建议楼主去sun的在线教程补一下SWING的基础。
      

  7.   

    JProjectList类里有下面这个方法:
    ---------------------------------
    public void mouseReleased(MouseEvent e) {
    try {
    if (!tree.isSelectionEmpty()) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
    if ((e.getModifiers() & java.awt.event.InputEvent.BUTTON3_MASK)
    != 0) {
    JPopupMenu menu = new JPopupMenu();
    PopupMenu(menu); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = menu.getPreferredSize(); // Flip along screen int x = e.getX();
    int y = e.getY(); menu.show(this,e.getX() - (int) jsppl.getViewport().getViewPosition().getX(),e.getY()- (int) jsppl.getViewport().getViewPosition().getY());
    } else if (e.getClickCount() == 1 && !node.isRoot()) {
    String pl = node.getUserObject().toString();
    firePropertyChange(SELECTED, "", pl);
    } else if (e.getClickCount() == 2 && !node.isRoot()) {
    try {
    if (!projects.containsKey(node.getUserObject().toString())) {
    frame = new hero.client.grapheditor.Frame(node.getUserObject().toString(),soapclient, false);
    frame.setSize(new Dimension(500, 400));
    frame.setVisible(true);
    projects.put(node.getUserObject().toString(),frame);
    frame.addPropertyChangeListener(PROJECTCLOSE, this);
    } else {
    frame =(hero.client.grapheditor.Frame) projects.get(node.getUserObject().toString());
    frame.requestFocus();
    }
    } catch (Exception ce) {
    //JOptionPane.showMessageDialog(null,resource.getString("jprojectlist.modify")+ node.getUserObject().toString()+ resource.getString("jprojectlist.proj"),resource.getString("jprojectlist.open"),JOptionPane.INFORMATION_MESSAGE,icon);
    }
    }
    }
    } catch (Exception e1){
    JOptionPane.showMessageDialog(null,resource.getString("jprojectlist.error"),resource.getString("jprojectlist.interror"),JOptionPane.INFORMATION_MESSAGE,icon);
    }
    }
    -----------------------------
    是不是这个方法体现的?!但,当发生双击projectList里的某个project时,是哪条语句调用了这个方法呢???
      

  8.   

    这句
    e.getClickCount() == 2这个代表双击,同时有不是根节点,产生一个新的frameif (e.getClickCount() == 2 && !node.isRoot()) {
    try {
    if (!projects.containsKey(node.getUserObject().toString())) {
    frame = new hero.client.grapheditor.Frame(node.getUserObject().toString(),soapclient, false);
    frame.setSize(new Dimension(500, 400));
    frame.setVisible(true);
    projects.put(node.getUserObject().toString(),frame);
    frame.addPropertyChangeListener(PROJECTCLOSE, this);
    }
      

  9.   

    此外JProjectList中应该有监听mouse事件的语句
      

  10.   

    thx!!!
    还是得好好补补swing的基础知识,除了sun的swing的tutorial,有没有哪本关于swing的比较新又比较好的书?!
      

  11.   

    www.amazon.com你搜一下SWING JAVA的前5本书都比较好,然后用Emule找一下下载,我有2本。还有Java2D对SWING也很重要。