bonjour , est-il possible d'avoir un jcombobox autocompletable en swingx? j'en ai entendu parlé mais je n'ai pas trouvé sur google. merci
bonjour , est-il possible d'avoir un jcombobox autocompletable en swingx? j'en ai entendu parlé mais je n'ai pas trouvé sur google. merci
Salut,
Tu as un exemple tout en bas de la page.
Bonjour , j'ai trouvé un script sur la complétion automatique:
http://xpose.avenir.asso.fr/viewxpos...ge=/swingX.php
Mais ça ne marche pas
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * TextFieldAutoComplete.java * * Created on Oct 25, 2009, 5:34:09 PM */ package swingx; import java.awt.List; import java.util.Vector; import javax.swing.JList; import javax.swing.JTextField; import org.jdesktop.swingx.autocomplete.Configurator; /** * * @author Administrator */ public class TextFieldAutoComplete extends javax.swing.JDialog { private final Configurator config = new org.jdesktop.swingx.autocomplete.Configurator(); /** Creates new form TextFieldAutoComplete */ public TextFieldAutoComplete(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); JTextField textField = new JTextField(); textField.setText("Remi"); /* On ajoute le manager qui fera la completion dans le textField avec les champs de la JList */ Vector v = new Vector(); v.add("Jimmy"); v.add("Julie"); v.add("Julien"); v.add("Juliette"); JList list = new JList(v); /* On ajoute le manager qui fera la completion dans le textField avec les champs de la JList */ Configurator.enableAutoCompletion(list, textField); this.add(textField); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jTextField1 = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jTextField1.setText("jTextField1"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(109, 109, 109) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(132, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(60, 60, 60) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(136, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(29, 29, 29) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(71, 71, 71)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(45, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(39, 39, 39)) ); pack(); }// </editor-fold> /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { TextFieldAutoComplete dialog = new TextFieldAutoComplete(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JPanel jPanel1; private javax.swing.JTextField jTextField1; // End of variables declaration }
Merci de chercher de détailler un tant soit peu l'erreur/le problème plutôt que de balancer un paquet de code de layout inutile à la compréhension du problème.
Accessoirement un tuto contenant les diverses méthodes permettant d'avoir de l'autocomplétion sur une JComboBox: http://today.java.net/pub/a/today/20...omboboxes.html
Accessoirement certaines des solutions marchent également pour des JTextFields
En l'occurence le papier que tu utilises comme référence date fortement et les API de SwingX ont changé depuis. http://swinglabs.org/hudson/job/SwingX Continuous Build/javadoc/org/jdesktop/swingx/autocomplete/AutoCompleteDecorator.html
Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager