bonsoir tout le monde
je vous demande comment ajouter jmenuitem sur JToolBar
par exemple si je click sur le bouton de JToolBar alors un menu s'ouvre
voilla le code
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.GridBagLayout;
import javax.swing.JToolBar;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.Font;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
public class menu extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel jPanel = null;
private JToolBar jJToolBarBar = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JButton jButton11 = null;
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBounds(new Rectangle(10, 15, 565, 216));
jPanel.add(getJJToolBarBar(), null);
}
return jPanel;
}
private JToolBar getJJToolBarBar() {
if (jJToolBarBar == null) {
jJToolBarBar = new JToolBar();
jJToolBarBar.setBounds(new Rectangle(40, 51, 424, 83));
jJToolBarBar.setBackground(new Color(0, 138, 255));
jJToolBarBar.setFloatable(false);
jJToolBarBar.setOrientation(JToolBar.HORIZONTAL);
jJToolBarBar.add(getJButton());
jJToolBarBar.add(getJButton11());
jJToolBarBar.add(getJButton1());
}
return jJToolBarBar;
}
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton(new ImageIcon("src/image/NOUVEAU.png"));
jButton.setFont(new Font("Dialog", Font.BOLD, 14));
jButton.setText(" ajouter ");
}
return jButton;
}
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setFont(new Font("Dialog", Font.BOLD, 12));
jButton1.setText(" supprimer ");
jButton1.setIcon(new ImageIcon(getClass().getResource("/SRC/IMAGE/NOUVEAU.PNG")));
}
return jButton1;
}
private JButton getJButton11() {
if (jButton11 == null) {
jButton11 = new JButton();
jButton11.setFont(new Font("Dialog", Font.BOLD, 14));
jButton11.setText(" modifier ");
jButton11.setIcon(new ImageIcon(getClass().getResource("/SRC/IMAGE/NOUVEAU.PNG")));
}
return jButton11;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
menu thisClass = new menu();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
public menu() {
super();
initialize();
}
private void initialize() {
this.setSize(605, 277);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJPanel(), null);
}
return jContentPane;
}
}
merci
Afficher la suite