IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AWT/Swing Java Discussion :

JTabbedPane insérer une icone sur l'onglet


Sujet :

AWT/Swing Java

  1. #1
    Membre averti Avatar de mouss4rs
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    884
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 884
    Points : 355
    Points
    355
    Par défaut JTabbedPane insérer une icone sur l'onglet
    bonjour a tous,

    j'aimerai inserer une icone sur le premier ongletet le probleme c'est que il ne trouve pas l'image.
    c'est une image en .png et j'aimerai savoir si c'est le format qu'il n'accepte pas car il me balance l'erreur du test de ma methode createImage(String path) :

    couldn't find file: "+path

    Voila ce que j'ai fait :

    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
    package modeles;
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.awt.Image;
    import java.awt.event.KeyEvent;
    
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    
    
    
    @SuppressWarnings("serial")
    public class Fenetre extends JPanel {
    
    	private JPanel jpa1, jpa2;
    	private JLabel jla1, jla2;
    	private JTextField login;
    	private JPasswordField password;
    	private JTabbedPane jtp;
    	private JButton bvalider;
    	private ImageIcon icon;
    
    	public Fenetre() {
    		super(new BorderLayout());
    		
    		jtp = new JTabbedPane(JTabbedPane.TOP);
    		icon = (ImageIcon) createImage("C:/Users/Oukna/Desktop/worskpaceTP/DiabetoMedical/connect.png");
    		
    		JComponent p1 = makeTextPanel("Connexion");
    		//jtp.setMnemonicAt(1, KeyEvent.VK_1);
    		
    		jpa1 = new JPanel();
    		jpa1.setLayout(new GridLayout(2,2));
    		jpa2 = new JPanel();
    		jpa2.setLayout(new FlowLayout());
    		
    		jla1 = new JLabel("Login: ");
    		jla2 = new JLabel("Password: ");
    		login = new JTextField(10);
    		password = new JPasswordField(10);
    		bvalider = new JButton("Submit");
    		jpa1.add(jla1);
    		jpa1.add(login);
    		jpa1.add(jla2);
    		jpa1.add(password);
    		jpa2.add(jpa1);
    		jpa2.add(bvalider);
    		
    		p1.add(jpa2);
    		jtp.addTab("Connexion", icon,p1);
    		
    		bvalider.addActionListener(new Ecouteur(1));
    		//login.addActionListener(new Ecouteur(2));
    		//password.addActionListener(new Ecouteur(2));
    		
    		
    		//add the tabbedpane to this panel
    		add(jtp);
    		
    		//the following line enables to use scrolling tabs
    		jtp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    		
    	}
    	protected JComponent makeTextPanel(String text) {
    		JPanel panel = new JPanel(false);
    		JLabel filler = new JLabel(text);
    		filler.setHorizontalAlignment(JLabel.CENTER);
    		panel.setLayout(new GridLayout(1, 1));
    		panel.add(filler);
    		return panel;
    	}
    	/** Returns an ImageIcon or null if the path was invalid.*/
    	protected static ImageIcon createImage(String path) {
    		java.net.URL imgURL = Fenetre.class.getResource(path);
    		if(imgURL != null){
    			return new ImageIcon(imgURL);
    		}else{
    		System.err.println("couldn't find file: "+path);
    		return null;
    	}
    	}
    	/**Create the GUI and show it. For thread safety.
    	 * this method should be invoked from
    	 * the event dispatch thread.
    	 */
    	private static void createAndShowGUI(){
    		//create and set up the window
    		JFrame frame = new JFrame("DiabetoMédical");
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		//Add content ti the window.
    		frame.add(new Fenetre(), BorderLayout.CENTER);
    		
    		//Display the window
    		frame.pack();
    		frame.setVisible(true);
    	}
    	public static void main(String[] args) {
            //Schedule a job for the event dispatch thread:
            //creating and showing this application's GUI.
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    //Turn off metal's use of bold fonts
    		UIManager.put("swing.boldMetal", Boolean.FALSE);
    		createAndShowGUI();
                }
            });
        }
    merci

  2. #2
    Membre averti Avatar de mouss4rs
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    884
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 884
    Points : 355
    Points
    355
    Par défaut
    J'ai vu que le format .png n'est pas pris en compte donc je l'ai converti en jpg puis en gif mais toujours rien .
    An Idea, please??

  3. #3
    Membre averti Avatar de mouss4rs
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    884
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 884
    Points : 355
    Points
    355
    Par défaut
    salut,

    J'ai trouver !
    en faites, il faut mettre l'image dans src.
    .png .gif .jpg sont accepté.


+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Insérer une icone sur un bouton
    Par mohamed2006 dans le forum Delphi
    Réponses: 5
    Dernier message: 14/09/2006, 09h03
  2. insérer une image sur une page html sans joindre son fichier
    Par fidji dans le forum Balisage (X)HTML et validation W3C
    Réponses: 9
    Dernier message: 03/02/2006, 10h15
  3. Réponses: 4
    Dernier message: 12/09/2005, 19h23
  4. mettre une JScrollBar sur un onglet
    Par thedd dans le forum Agents de placement/Fenêtres
    Réponses: 4
    Dernier message: 02/03/2004, 20h12
  5. [icone]Comment appliquer une icone sur le.exe
    Par JavaLeDirePartout dans le forum JBuilder
    Réponses: 7
    Dernier message: 24/07/2003, 17h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo