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 :

inclure dans une image du textarea


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Battosaiii
    Invité(e)
    Par défaut inclure dans une image du textarea
    Voi j'arrive a afficher dans Jframe une image. Le probleme qui se pose s'est inclure dans cette image du textarea. Or lorsque aue j'ajoute l'image et le textarea dans un panel, le textarea est "absorbe". c'est a dire qu'on ne le voit plus !

    Voici un morecaue du code :

    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
    	   private BufferedImage image; 
     
    	public SwingImageButton() 
    	{
    		  super("Swing Button Example");
     
     
    	/*Load an image */
    	String filename="portable.JPG";
    	  image = new BufferedImage(290, 470, BufferedImage.TYPE_INT_RGB);
        // create an image by reading in the PNG, GIF, or JPEG from a filename
            try { image = ImageIO.read(new File(filename)); }
            catch(IOException e) {
                e.printStackTrace();
                throw new RuntimeException("Could not open file: " + filename);
            }
            if (image == null)
                throw new RuntimeException("Invalid image file: " + filename);
    	ImageIcon icon = new ImageIcon(image);
    			JLabel j = new JLabel(icon);
    	  JPanel controls = new JPanel(new FlowLayout());
    	  this.button = new JButton("Clear Text");
    	  this.button.addActionListener(this);	
    	  j.add(this.button);
     
    	  editable = new JCheckBox("Read-Only");
    	  editable.addActionListener(this);
    	  j.add(this.editable);
     
    	  controls.add(new JLabel("  Text Color:"));
    	  String[] items = {"Black", "Blue", "Green", "Red"};
    	  colorBox = new JComboBox(items);
    	  colorBox.addActionListener(this);
    	  controls.add(colorBox);
    	  this.status = new JTextField();
    	  this.updateStatus("Application Started.");
     
    	  // main area, with scrolling and wrapping
     
    	  this.textArea = new JTextArea(20,40);
    	  JScrollPane p = new JScrollPane(this.textArea,
    			JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
    			JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    	  this.textArea.setWrapStyleWord(true);
    j.add(p);
     
    	  this.getContentPane().add("North",controls);
    	  this.getContentPane().add("South",j);
    	  this.pack();  //set the size of the frame according 
    			//to the component's preferred sizes
    	  this.show();

  2. #2
    Membre expérimenté Avatar de aDamas
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    260
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2004
    Messages : 260
    Par défaut
    Y a un truc que je capte pas, tu as tout mis dans un JLabel?? Je sais pas si c'est très propre en général on utilise des JPanels...

    peut-être en faisant :

    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
    public class monTextArea extends JTextArea
    {
    private Image bgImage;
    public monTextArea(Image bgImage,...)// ajouter les paramètre utiles
    {
    super(...)//paramètre du constructeur de JTextArea.
    this.bgImage=bgImage;
    }
     
    public void paintComponent(Graphics g)
    {
    g.drawImage(bgImage,0,0,null);
    super.paintComponent(g);//après pour que l'image soit sous le texte
    }
    }
    Et tu remplace ton ancien JTextArea par le nouveau monTextArea.

    J'ai pas testé je suis pas sûr que l'image soit toujours visible avec le texte... Enfin, c'est une idée.

  3. #3
    Battosaiii
    Invité(e)
    Par défaut
    J'ai essaye mais super.paintcomponent(g) me donne des erreurs.
    Pour l\instant je vais tente d'afficher l'image sans rioen d'autre et j'arrive avec paintcomponent

    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
    public class SwingImageButton extends JFrame implements ActionListener
      {
     
     
    	//private Image theImage;
    	private JButton button;
    	private JTextArea textArea;
    	private JTextField status;
    	private JCheckBox editable;
    	private JComboBox colorBox;
    	private boolean isTextEditable = true;
    	//private JComboBo
    	   private BufferedImage image; 
     
    	public SwingImageButton() 
    	{
    		  super("Swing Button Example");
     
     
    	/*Load an image */
    	String filename="portable.JPG";
    	  image = new BufferedImage(290, 470, BufferedImage.TYPE_INT_RGB);
        // create an image by reading in the PNG, GIF, or JPEG from a filename
            try { image = ImageIO.read(new File(filename)); }
            catch(IOException e) {
                e.printStackTrace();
                throw new RuntimeException("Could not open file: " + filename);
            }
     
     
    	  // status TextField
    	  this.status = new JTextField();
    	  this.updateStatus("Application Started.");
     
    	  // main area, with scrolling and wrapping
     
    	  this.textArea = new JTextArea(20,40);
    	  JScrollPane p = new JScrollPane(this.textArea,
    			JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
    			JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    	  this.textArea.setWrapStyleWord(true);
     
    	  this.getContentPane().add("North",p);
     
    	  this.pack();  //set the size of the frame according 
    			//to the component's preferred sizes
    	  this.show();	//make the frame visible
     
    	}
    	private void updateStatus(String theStatus)
    	{
    	  this.status.setText("Status: " + theStatus);
    	}
    	public void actionPerformed(ActionEvent e)
    	{
     
    	}
     
    	public void paintComponent(Graphics g)
    	{
    	//super(g);
     
    Graphics2D g2D=(Graphics2D )g;
    Graphics2D g2d = (Graphics2D)this.image.getGraphics();
    //g2D.drawImage(this.image,20,40,this);
    //super.paintComponent(g);
    	//	g.drawImage( this.tempImage, 10, 10, this);
    	}
     
    	public static void main(String args[])
    	{
    	   new SwingImageButton();
    	}
      }
    je me suis inspire du faq mais ca veut pas marcher malgre tout !

  4. #4
    Membre expérimenté Avatar de aDamas
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    260
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2004
    Messages : 260
    Par défaut
    ... bon je sais plus trop où répondre, sur ce topic ou sur l'autre enfin peut importe...

    On c'est mal compris c'est normal que ton code ne fonctionne pas, ce n'est pas la méthode paintComponent(Graphics g) de la classe JFrame que tu dois redéfinir(ce que tu as fait ici) parce qu'elle n'existe pas,... mais celle de ton JPanel.

Discussions similaires

  1. Détection position des yeux dans une image
    Par Morvan Mikael dans le forum Traitement d'images
    Réponses: 16
    Dernier message: 24/12/2008, 23h09
  2. Zone de texte dans une image
    Par sanna dans le forum Algorithmes et structures de données
    Réponses: 21
    Dernier message: 18/03/2005, 22h15
  3. [FLASH 5]un bouton dans une image pour revenir sur une scene
    Par patato valdes dans le forum Flash
    Réponses: 7
    Dernier message: 28/04/2004, 20h21
  4. Obtenir la position du curseur dans une Image
    Par bastoune dans le forum Composants VCL
    Réponses: 6
    Dernier message: 14/11/2003, 21h02
  5. faire un selection dans une image aves les APIs
    Par merahyazid dans le forum C++Builder
    Réponses: 3
    Dernier message: 30/04/2002, 10h44

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