Rechercher : dans
Par :

Création d'un ChekboxGroup avec java

Dernière réponse le 22 jui 2008 à 09:58:09 minos11, le 21 jui 2008 à 12:05:29 
 Signaler ce message aux modérateurs

Bonjour,
quel est le code java permettant d'écrire la liste des choix dans un ChekboxGroup et d'afficher ce dernier sur mon interface?Aidez moi s'il vous plait.
Merci

Configuration: Windows XP
Internet Explorer 6.0

Meilleures réponses pour « Création d'un ChekboxGroup avec java » dans :
[Firefox] plugin Java Jre de Sun VoirA) Les différentes variantes Java chez Sun B) Installation sous Mandriva Limited Edition 2005 ETAPE 1 ETAPE 2: Création du lien symbolique C) Installation sous debian lenny D) Installation sous ubuntu hardy heron A) Les différentes...
[Logiciel libre] Installation firefox 2.0+java+flash VoirInstallation firefox 2.0+java+flash en ligne de commande A. INTRODUCTION B. INSTALLATION FIREFOX 1. Création d'environnement 2. Téléchargement et vérification de la signature 3. Installation de Firefox 4. Démarrage de l'application C....
Java: les variables VoirLe concept de variable Une variable est un objet repéré par son nom, pouvant contenir des données, qui pourront être modifiées lors de l'exécution du programme. Les variables en langage Java sont typées, c'est-à-dire que les données contenues dans...
Introduction aux Java Server Pages VoirPrésentation des Java Server Pages Les JSP (Java Server Pages) sont un standard permettant de développer des applications Web interactives, c'est-à-dire dont le contenu est dynamique. C'est-à-dire qu'une page web JSP (repérable par l'extension...

1

sandul, le 21 jui 2008 à 15:18:49

Salut,

Pourquoi pas qqch du genre

		ButtonGroup bg = new ButtonGroup();
		bg.add(getConnectionAdminRB());
		bg.add(getConnectionHistRB());
		bg.add(getConnectionNormRB());


où les méthodes get retournent des JRadioButton? Ceci marche également pour des JCheckBox à la place des boutons radio (mais moins courant de les utiliser dans une interface si des choix à faire sont mutuellement exclusifs).

HTH,
++

Répondre à sandul

2

minos11, le 22 jui 2008 à 07:19:49

Bonjour,
merci pour votre aide,je vais essayer avec le code que vous m'avez indiqué

Répondre à minos11

3

minos11, le 22 jui 2008 à 07:38:36

Bonjour,
J'ai essayé le code que vous m'avez indiqué:
ButtonGroup bg = new ButtonGroup();
bg.add(getConnectionAdminRB());
bg.add(getConnectionHistRB());
bg.add(getConnectionNormRB());
mais il me donne cette erreur:can not resolve symbol method getConnectionAdminRB()
can not resolve symbol method getConnectionHistRB()
can not resolve symbol method getConnectionNormRB()
est ce qu'il y a une bibliothèque que je dois ajouter ou quoi?
Une autre question stp,comment je peux ecrire ma liste de choix et l'afficher dans le CheckBox?
Merci.

Répondre à minos11

4

 sandul, le 22 jui 2008 à 09:58:09

Les 3 méthodes get retournent un JRadioButton (ou une JCheckBox, si tu y tiens) ==> remplacer avec tes propres radio boutons ou checkbox.

Une autre question stp,comment je peux ecrire ma liste de choix et l'afficher dans le CheckBox? ==> là je ne comprends pas trop, est-ce que tu parles d'une ComboBox??

En tout cas, voici un petit exemple montrant l'utilisation des boutons radio, des checkboxes et d'une JComboBox, j'espère que cela sera plus clair:

package minos11.test;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class MinosSample extends JFrame {
	private static final long serialVersionUID = 1L;
	private JComboBox comboBox;

	/**
	 * Launch the application
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			MinosSample frame = new MinosSample();
			frame.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the frame
	 */
	public MinosSample() {
		super();
		setBounds(100, 100, 500, 375);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		final JPanel centerPane = new JPanel();
		final GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.rowHeights = new int[] { 0, 7, 7 };
		centerPane.setLayout(gridBagLayout);
		getContentPane().add(centerPane);

		final JRadioButton radioButton = new JRadioButton();
		radioButton.setText("New JRadioButton");
		final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints();
		gridBagConstraints_4.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints_4.anchor = GridBagConstraints.WEST;
		centerPane.add(radioButton, gridBagConstraints_4);

		final JRadioButton radioButton_1 = new JRadioButton();
		radioButton_1.setText("New JRadioButton");
		final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints();
		gridBagConstraints_5.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints_5.anchor = GridBagConstraints.WEST;
		centerPane.add(radioButton_1, gridBagConstraints_5);

		final JRadioButton radioButton_2 = new JRadioButton();
		radioButton_2.setText("New JRadioButton");
		final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints();
		gridBagConstraints_6.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints_6.anchor = GridBagConstraints.WEST;
		centerPane.add(radioButton_2, gridBagConstraints_6);

		final JCheckBox checkBox = new JCheckBox();
		checkBox.setText("New JCheckBox");
		final GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.gridx = 0;
		centerPane.add(checkBox, gridBagConstraints);

		final JCheckBox checkBox_1 = new JCheckBox();
		checkBox_1.setText("New JCheckBox");
		final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
		gridBagConstraints_1.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints_1.anchor = GridBagConstraints.WEST;
		gridBagConstraints_1.gridy = 1;
		gridBagConstraints_1.gridx = 1;
		centerPane.add(checkBox_1, gridBagConstraints_1);

		final JCheckBox checkBox_2 = new JCheckBox();
		checkBox_2.setText("New JCheckBox");
		final GridBagConstraints gridBagConstraints_2 = new GridBagConstraints();
		gridBagConstraints_2.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints_2.anchor = GridBagConstraints.WEST;
		gridBagConstraints_2.gridy = 1;
		gridBagConstraints_2.gridx = 2;
		centerPane.add(checkBox_2, gridBagConstraints_2);

		comboBox = new JComboBox();
		final GridBagConstraints gridBagConstraints_3 = new GridBagConstraints();
		gridBagConstraints_3.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints_3.anchor = GridBagConstraints.WEST;
		gridBagConstraints_3.gridy = 2;
		gridBagConstraints_3.gridx = 0;
		centerPane.add(comboBox, gridBagConstraints_3);

		final JPanel southPane = new JPanel();
		final FlowLayout flowLayout = new FlowLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		southPane.setLayout(flowLayout);
		getContentPane().add(southPane, BorderLayout.SOUTH);

		final JButton okButton = new JButton();
		okButton.setText("OK");
		southPane.add(okButton);

		// On rajoute les 3 radio buttons au 1er group, les trois checkboxes ou 2ème group et on remplit le combo
		ButtonGroup bg1 = new ButtonGroup();
		ButtonGroup bg2 = new ButtonGroup();
		bg1.add(radioButton);
		bg1.add(radioButton_1);
		bg1.add(radioButton_2);

		bg2.add(checkBox);
		bg2.add(checkBox_1);
		bg2.add(checkBox_2);

		DefaultComboBoxModel model = new DefaultComboBoxModel();
		model.addElement("1er élément");
		model.addElement("2ème élément");
		model.addElement("3ème élément");
		comboBox.setModel(model);
		//
	}
}


Ciao

Répondre à sandul