Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6459824

Add an "image" property to controls like the JPanel, JButton, etc...

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P5 P5
    • None
    • 5.0, 6
    • client-libs

      A DESCRIPTION OF THE REQUEST :
      At the moment you need to write a lot of code to put an image as background in a control. I think will be really good to re-design some controls to allow panels, buttons or frames to include an "image propery" to set it easy in NetBeans/JStudio a JPG/GIF/PNG image as background like in the JLabel. Atm you have to implement custom controls or override the paint method which is tedious. Why the JLabel has the "Icon" image option and other basic controls like the JPanel or the JButton not? You should put an "ImageBackground" property in the base swing control(JComponent object perhaps??)

      JUSTIFICATION :
      Other technologies like Cocoa or .NET have implemented MUCH better image background control. The JFCs lacks an EASY mechanism to do a super-basic-thing like to set a panel background. You should improve better the Java standard UI controls our you will loose competitivity. Atm our team is using .NET because is too hard to do simple things with Swing like this "set easy a control background image"... In .NET is one mouse click and link to the image... In Java you have to implement your curstom control or to override the paint method....

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Open your favourite Java IDE GUI editor ( NetBeans, JStudio... ). Open your JFrame. Select a control. Click in the "ImageBackground" property and set a JPG/GIF/PNG/BMP image file and voila... control's image background will be set like you are doing atm in the JLabel control...
      ACTUAL -
      You have to implement your custom control or to override the control's paint method to do a super-basic-thing like to set a control image background. Too complicated.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.image.*;
      import javax.swing.*;

      public class ImagePanel extends JPanel {

          private Image img;

          public ImagePanel() {
      this.setBackground(Color.white);
      //setSize(new Dimension(300, 200));
          }

          //painting Methods
          public void paintComponent(Graphics g) {
      update(g);
          }
          
          public void update(Graphics g) {
      Graphics2D g2 = (Graphics2D)g;
      g2.setColor(this.getBackground());
      g2.fillRect(0,0, this.getWidth(), this.getHeight());
      if (img != null)
      g2.drawImage(img,0,0,this);
      else System.out.println(img==null);

          }

          public void setImage(Image src) {
      this.img=null;
      this.img=src;
      repaint();
          }

          public Dimension getPreferredSize() {

      return new Dimension(img.getWidth(this), img.getHeight(this));
          }
          
          public Dimension getMinimumSize() {
      return new Dimension(img.getWidth(this), img.getHeight(this));
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Sun should include a java.awt.ImagePanel or a javax.swing.ImagePanel basic control or include a property like "imageBackground" in the JComponent class so you could do:

      JButton button = new JButton("ClickMe!");
      button.image = new Image("button1.jpg")

      and ofc upgrade NetBeans to mouse-click over this property and browse an image for you...

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: