begin process at 2010 03 21 02:26:11
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Api

 > SELECTIONLISTSPANEL

SELECTIONLISTSPANEL


 Information sur la source

Note :
4 / 10 - par 1 personne
4,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Api Classé sous :jlist, jpanel, selection, copie Niveau :Débutant Date de création :06/06/2002 Date de mise à jour :06/06/2002 12:05:12 Vu / téléchargé :5 065 / 410

Auteur : trap

Ecrire un message privé
Site perso
Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

 Description

Panneau intégrant deux listes permettant la selection d'éléments de l'une vers l'autre.

Source

  • package com.infodavid.gui;
  • /*
  • * Copyright (c) 2001 David Rolland
  • *
  • * Redistribution and use in source and binary forms, with or without
  • * modification, are permitted provided that the following conditions are met:
  • *
  • * -Redistributions of source code must retain the above copyright notice, this
  • * list of conditions and the following disclaimer.
  • *
  • * -Redistribution in binary form must reproduct the above copyright notice,
  • * this list of conditions and the following disclaimer in the documentation
  • * and/or other materials provided with the distribution.
  • *
  • * This software is provided "AS IS," without a warranty of any kind. ALL
  • * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  • * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  • * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. D.Rolland SHALL NOT BE
  • * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  • * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL D.Rolland
  • * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  • * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  • * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  • * OR INABILITY TO USE SOFTWARE, EVEN IF D.Rolland HAS BEEN ADVISED OF THE
  • * POSSIBILITY OF SUCH DAMAGES.
  • *
  • * You acknowledge that Software is not designed,licensed or intended for use in
  • * the design, construction, operation or maintenance of any nuclear facility.
  • */
  • import javax.swing.JSplitPane;
  • import javax.swing.JList;
  • import javax.swing.JButton;
  • import java.awt.dnd.*;
  • import java.awt.BorderLayout;
  • import java.awt.event.ActionEvent;
  • import java.awt.event.ActionListener;
  • import sun.net.www.MimeEntry;
  • import java.beans.PropertyVetoException;
  • /* infodavid */
  • import com.infodavid.lang.LanguageObject;
  • import com.infodavid.lang.Language;
  • import com.infodavid.gui.events.ActionToChangeListener;
  • import com.infodavid.gui.events.ActionToDropListener;
  • /**
  • * Title:
  • * Description:
  • * Copyright: Copyright (c) 2001
  • * Company: David Rolland, infodavid@chez.com
  • * @author David Rolland, infodavid@chez.com
  • * @version 0.2
  • */
  • public class SelectionListsPanel extends AbstractPanel {
  • private class DefaultGlobalListTargetListener extends ActionToDropListener {
  • public DefaultGlobalListTargetListener(ActionListener al) { super(al); }
  • public boolean isDragAcceptable(DropTargetEvent e) {
  • return (adding || removing) && isEnabled();
  • }
  • public boolean isDropAcceptable(DropTargetEvent e) {
  • return adding && isEnabled();
  • }
  • public void dragEnter(DropTargetDragEvent e) {
  • removing = false;
  • if (!isDragAcceptable(e)) {
  • e.rejectDrag();
  • }
  • }
  • public void dragExit(DropTargetEvent e) {
  • if (adding) {
  • adding = false;
  • }
  • else {
  • removing = true;
  • }
  • }
  • public void drop(DropTargetDropEvent e) {
  • if (!isDropAcceptable(e)) {
  • e.rejectDrop();
  • }
  • else {
  • e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
  • super.drop(e);
  • adding = false;
  • e.dropComplete(true);
  • }
  • }
  • }
  • private class DefaultSelectionListTargetListener extends ActionToDropListener {
  • public DefaultSelectionListTargetListener(ActionListener al) { super(al); }
  • public boolean isDragAcceptable(DropTargetEvent e) {
  • return (adding || removing) && isEnabled();
  • }
  • public boolean isDropAcceptable(DropTargetEvent e) {
  • return removing && isEnabled();
  • }
  • public void dragEnter(DropTargetDragEvent e) {
  • adding = false;
  • if (!isDragAcceptable(e)) {
  • e.rejectDrag();
  • }
  • }
  • public void dragExit(DropTargetEvent e) {
  • if (removing) {
  • removing = false;
  • }
  • else {
  • adding = true;
  • }
  • }
  • public void drop(DropTargetDropEvent e) {
  • if (!isDropAcceptable(e)) {
  • e.rejectDrop();
  • }
  • else {
  • e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
  • super.drop(e);
  • removing = false;
  • e.dropComplete(true);
  • }
  • }
  • }
  • private ListPanel selectionPanel = null;
  • private ListPanel globalPanel = null;
  • private JButton add = null;
  • private JButton remove = null;
  • private boolean removing = false;
  • private boolean adding = false;
  • /**
  • * Constructeur
  • *
  • * @param Language Dictionnaire
  • * @param int Orientation
  • * @exception PropertyVetoException Exception liée à la validité du dictionnaire
  • */
  • public SelectionListsPanel(Language lang, int orientation) throws PropertyVetoException {
  • if (lang == null) {
  • throw new IllegalArgumentException(getClass().getName() +
  • "." + getClass().getName() + "(Language)");
  • }
  • initializePanel(lang, orientation);
  • }
  • /**
  • * Non disponible
  • *
  • * @exception IllegalAccessError Exception liée a la non implementation
  • */
  • public MimeEntry[] getMimeType() {
  • throw new IllegalAccessError(getClass().getName() +
  • ".getMimeType(), not used !");
  • }
  • public ListPanel getSelectionPanel() { return selectionPanel; }
  • public JList getSelectionList() { return getSelectionPanel().getList(); }
  • public JList getGlobalList() { return getGlobalPanel().getList(); }
  • public ListPanel getGlobalPanel() { return globalPanel; }
  • private void initializePanel(Language language, int orientation)
  • throws PropertyVetoException {
  • LanguageObject lang = null;
  • selectionPanel = new ListPanel();
  • remove = new JButton();
  • lang = language.get("Remove", remove);
  • selectionPanel.getContentPanel().add(remove, BorderLayout.SOUTH);
  • globalPanel = new ListPanel();
  • add = new JButton();
  • lang = language.get("Add", add);
  • globalPanel.getContentPanel().add(add, BorderLayout.SOUTH);
  • JSplitPane splitPane = new JSplitPane(
  • orientation,
  • selectionPanel.getContentPanel(),
  • globalPanel.getContentPanel()
  • );
  • splitPane.setContinuousLayout(true);
  • splitPane.setDoubleBuffered(true);
  • splitPane.setOneTouchExpandable(true);
  • setContentComponent(splitPane);
  • }
  • public void addActionListener(ActionListener l) {
  • super.addActionListener(l);
  • selectionPanel.addActionListener(l);
  • globalPanel.addActionListener(l);
  • add.addActionListener(l);
  • remove.addActionListener(l);
  • JList list = (JList)selectionPanel.getContentComponent();
  • list.setDragEnabled(true);
  • list.setDropTarget(
  • new DropTarget(
  • list,
  • new DefaultSelectionListTargetListener(l)
  • )
  • );
  • list = (JList)globalPanel.getContentComponent();
  • list.setDragEnabled(true);
  • list.setDropTarget(
  • new DropTarget(
  • list,
  • new DefaultGlobalListTargetListener(l)
  • )
  • );
  • }
  • public void removeActionListener(ActionListener l) {
  • super.removeActionListener(l);
  • add.removeActionListener(l);
  • remove.removeActionListener(l);
  • selectionPanel.removeActionListener(l);
  • globalPanel.removeActionListener(l);
  • JList list = (JList)selectionPanel.getContentComponent();
  • list.setDropTarget(null);
  • list = (JList)globalPanel.getContentComponent();
  • list.setDropTarget(null);
  • }
  • public static void main(String[] args) {
  • try {
  • javax.swing.JFrame f = new javax.swing.JFrame();
  • SelectionListsPanel p = new SelectionListsPanel(new Language(), JSplitPane.HORIZONTAL_SPLIT);
  • p.setTitle("Test");
  • p.getGlobalPanel().setTitle("Global");
  • p.getSelectionPanel().setTitle("Selection");
  • p.addActionListener(new ActionListener() {
  • public void actionPerformed(ActionEvent e) {
  • System.out.println(e);
  • }
  • });
  • JList list = p.getGlobalList();
  • list.setListData(new String[] { "item1" });
  • list = p.getSelectionList();
  • list.setListData(new String[] { "item2", "item3" });
  • f.getContentPane().add(p.getContentPanel());
  • f.pack();
  • f.show();
  • } catch (Exception e) { e.printStackTrace(); }
  • }
  • }
package com.infodavid.gui;
/*
 * Copyright (c) 2001 David Rolland
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * -Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * -Redistribution in binary form must reproduct the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. D.Rolland SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL D.Rolland
 * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF D.Rolland HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that Software is not designed,licensed or intended for use in
 * the design, construction, operation or maintenance of any nuclear facility.
 */
import javax.swing.JSplitPane;
import javax.swing.JList;
import javax.swing.JButton;

import java.awt.dnd.*;

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import sun.net.www.MimeEntry;

import java.beans.PropertyVetoException;

/* infodavid */
import com.infodavid.lang.LanguageObject;
import com.infodavid.lang.Language;

import com.infodavid.gui.events.ActionToChangeListener;
import com.infodavid.gui.events.ActionToDropListener;
/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      David Rolland, infodavid@chez.com
 * @author       David Rolland, infodavid@chez.com
 * @version 0.2
 */
public class SelectionListsPanel extends AbstractPanel {
  private class DefaultGlobalListTargetListener extends ActionToDropListener {
    public DefaultGlobalListTargetListener(ActionListener al) { super(al); }

    public boolean isDragAcceptable(DropTargetEvent e) {
      return (adding || removing) && isEnabled();
    }

    public boolean isDropAcceptable(DropTargetEvent e) {
      return adding && isEnabled();
    }

    public void dragEnter(DropTargetDragEvent e) {
      removing = false;

      if (!isDragAcceptable(e)) {
        e.rejectDrag();
      }
    }

    public void dragExit(DropTargetEvent e) {
      if (adding) {
        adding = false;
      }
      else {
        removing = true;
      }
    }

    public void drop(DropTargetDropEvent e) {
      if (!isDropAcceptable(e)) {
        e.rejectDrop();
      }
      else {
        e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

        super.drop(e);

        adding = false;

        e.dropComplete(true);
      }
    }
  }

  private class DefaultSelectionListTargetListener extends ActionToDropListener {
    public DefaultSelectionListTargetListener(ActionListener al) { super(al); }

    public boolean isDragAcceptable(DropTargetEvent e) {
      return (adding || removing) && isEnabled();
    }

    public boolean isDropAcceptable(DropTargetEvent e) {
      return removing && isEnabled();
    }

    public void dragEnter(DropTargetDragEvent e) {
      adding = false;

      if (!isDragAcceptable(e)) {
        e.rejectDrag();
      }
    }

    public void dragExit(DropTargetEvent e) {
      if (removing) {
        removing = false;
      }
      else {
        adding = true;
      }
    }

    public void drop(DropTargetDropEvent e) {
      if (!isDropAcceptable(e)) {
        e.rejectDrop();
      }
      else {
        e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

        super.drop(e);

        removing = false;

        e.dropComplete(true);
      }
    }
  }

  private ListPanel selectionPanel = null;
  private ListPanel globalPanel = null;
  private JButton add = null;
  private JButton remove = null;
  private boolean removing = false;
  private boolean adding = false;

  /**
   * Constructeur
   *
   * @param Language Dictionnaire
   * @param int Orientation
   * @exception PropertyVetoException Exception liée à la validité du dictionnaire
   */
  public SelectionListsPanel(Language lang, int orientation) throws PropertyVetoException {
    if (lang == null) {
      throw new IllegalArgumentException(getClass().getName() +
       "." + getClass().getName() + "(Language)");
    }

    initializePanel(lang, orientation);
  }

  /**
   * Non disponible
   *
   * @exception IllegalAccessError Exception liée a la non implementation
   */
  public MimeEntry[] getMimeType() {
    throw new IllegalAccessError(getClass().getName() +
      ".getMimeType(), not used !");
  }

  public ListPanel getSelectionPanel() { return selectionPanel; }

  public JList getSelectionList() { return getSelectionPanel().getList(); }

  public JList getGlobalList() { return getGlobalPanel().getList(); }

  public ListPanel getGlobalPanel() { return globalPanel; }

  private void initializePanel(Language language, int orientation)
    throws PropertyVetoException {

    LanguageObject lang = null;

    selectionPanel = new ListPanel();
    remove = new JButton();
    lang = language.get("Remove", remove);
    selectionPanel.getContentPanel().add(remove, BorderLayout.SOUTH);

    globalPanel = new ListPanel();
    add = new JButton();
    lang = language.get("Add", add);
    globalPanel.getContentPanel().add(add, BorderLayout.SOUTH);

    JSplitPane splitPane = new JSplitPane(
      orientation,
      selectionPanel.getContentPanel(),
      globalPanel.getContentPanel()
    );

    splitPane.setContinuousLayout(true);
    splitPane.setDoubleBuffered(true);
    splitPane.setOneTouchExpandable(true);

    setContentComponent(splitPane);
  }

   public void addActionListener(ActionListener l) {
    super.addActionListener(l);

    selectionPanel.addActionListener(l);
    globalPanel.addActionListener(l);

    add.addActionListener(l);
    remove.addActionListener(l);

    JList list = (JList)selectionPanel.getContentComponent();
    list.setDragEnabled(true);
    list.setDropTarget(
      new DropTarget(
        list,
        new DefaultSelectionListTargetListener(l)
      )
    );

    list = (JList)globalPanel.getContentComponent();
    list.setDragEnabled(true);
    list.setDropTarget(
      new DropTarget(
        list,
        new DefaultGlobalListTargetListener(l)
      )
    );
  }

  public void removeActionListener(ActionListener l) {
    super.removeActionListener(l);

    add.removeActionListener(l);
    remove.removeActionListener(l);

    selectionPanel.removeActionListener(l);
    globalPanel.removeActionListener(l);

    JList list = (JList)selectionPanel.getContentComponent();
    list.setDropTarget(null);

    list = (JList)globalPanel.getContentComponent();
    list.setDropTarget(null);
  }

  public static void main(String[] args) {
    try {
    javax.swing.JFrame f = new javax.swing.JFrame();
    SelectionListsPanel p = new SelectionListsPanel(new Language(), JSplitPane.HORIZONTAL_SPLIT);

    p.setTitle("Test");
    p.getGlobalPanel().setTitle("Global");
    p.getSelectionPanel().setTitle("Selection");



    p.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.out.println(e);
      }
    });

    JList list = p.getGlobalList();
    list.setListData(new String[] { "item1" });

    list = p.getSelectionList();
    list.setListData(new String[] { "item2", "item3" });

    f.getContentPane().add(p.getContentPanel());
    f.pack();
    f.show();
    } catch (Exception e) { e.printStackTrace(); }
  }
}

 Conclusion

Tester le main...

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

GUICHRONOMETER
CHRONOMETER

 Sources de la même categorie

Source avec Zip Source avec une capture LETMESEE : CAPTURE D'ÉCRAN À INTERVALLE RÉGULIER : UTILISATI... par pyo656
ENVOI D'UNE ARBORESSENCE EN JAVA VERS SERVEUR FTP par moumou95
ENREGISTRER L'ARBORESCENCE D'UN JTREE DANS UN XML AVEC JDOM par coltman
Source avec Zip WIZARD JAVA API par aissam36
JCONFIGURATIONMANAGER - GESTION DES CONFIGURATIONS par Francks11

 Sources en rapport avec celle ci

RECHERCHE D'ELEMENTS DANS UNE JLIST par Ze_Hulk
JPANEL TEXTE DÉFILANT : MARQEE EN JAVA par co2_gaz
Source avec Zip Source avec une capture PETIT PROGRAMME DE COPIE RAPIDE DE FICHIER par cadjak
Source avec Zip Source avec une capture UN JTEXTPANE NOTICE : JEU DE STYLES PRÉDÉFINIS ET INSERTION ... par loloof64
Source avec Zip SÉLECTION MULTIPLE AVEC JLIST ET COPIE D'ÉLÉMENTS D'UNE LIST... par Jackboy

Commentaires et avis

Commentaire de jafouille94 le 02/09/2004 15:54:52

salut mec , g essayé ta source ms qd je veu ajouter l'item 2 ou 3 o panel droite, ca marche pas et pareil qd je veu supprimer...
tu peu m'expliker comment marche ta source stp car des q je la lance g une erreur ki di :  


com.infodavid.lang.Language.getFirst(LanguageObject, String, boolean), No word found in dictionnary for remove !

com.infodavid.lang.Language.getFirst(LanguageObject, String, boolean), No word found in dictionnary for add !


donc moi pas comprendre lol!!!

de plus j'ai grave besoin de ce type de methode. demain c mon dernier jour de stage et g un truc comme ca a implementer..
merci de repondre assez vite stp
et jolie source!

Commentaire de lord_snotling le 04/03/2006 12:42:54

je trouve que ta source manque cruellement de commentaire et ce n'est pas facile de tout comprendre surtout pour un débutant comme moi

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

JList et selection [ par tof008 ] Bonjour à tous!J'ai un problème qui me bloque depuis quelques heures : Je veux pouvoir selectionner un element d'une JList, mais a chaque fois que je Jlist selection [ par scaryman ] bonour je voudrais savoir comment désactiver la selection d'une entrée de JList par appui sur une touche du clavier. Merci ++ evenement après selection dans une jlist [ par bygui ]    Bonjour,voila j'aimerais appelé une methode à chaque fois que l'utilisateur selectionne un element d'une liste.Je dois san Une JList de JPanel [ par frater_sinister ] Bonjour,J'ai un petit soucis avec les Jlist. J'arriver a les manipuler avec des elements String mais pas avec des éléments JPanel. Mon code source:imp Problème de JList [ par GillesWebmaster ] Bonsoir ,J'ai un problème de JList:      je crées une JList sans aucun problème mais je n'arrive pas&nbsp Annuler une sélection [ par jarod34 ] Bonjour, J'ai un Jpanel dans lequel j'affiche des miniatures. Je peut les selectionner pour les renommers. Mon problème c'est qu'une fois séléction Insérer un JPanel dans une JInternalFrame sous NetbBeans [ par crazysetup ] Bonjour à tous Voici mon souci : Je développe une application de gestion et simulation d'un championnat de football sous NetBeans en utilisant le co JFrame, Menu, JPanel ... [ par Mordikkuss ] Bonsoir, étant débutant, question de débutant: j'ai une fenêtre avec un menu, dans ce menu, j'ai un item qui me permet d'ajouter un JPanel, ça c'est JGraph et selection cellule [ par petivorka ] Bonjour, Je développe un logiciel en java à l'aide de JGraph et j'ai rencontré un problème : c'est de savoir quelle cellule est sélectionnée quand o Probleme de addMouseListener en JPanel [ par lkgreg ] Salut tout le monde, comme le dis le titre mon problème consiste à appliquer le addMouseListener à JPanel, bizarre que ça marche pas!! sachant


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,655 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales