Image on the panel

Hi Experts,
I am in the midst of getting an image onto a frame hence have some difficulty, I seek your assistance to place an image on the left of the message. The code is append for your advice, please.
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
public class Help implements ActionListener {
Frame frame = new Frame ("Help");
Button okButton = new Button ("Ok");
public Help() {
Panel buttonPanel = new Panel ();
buttonPanel.add (okButton);
okButton.addActionListener (this);
frame.setLayout(new BorderLayout());
Panel messagePanel = new Panel();
messagePanel.setLayout(new GridLayout(14,1));
messagePanel.add(new Label("Sentence 1 - I want to put an image on my left"));
messagePanel.add(new Label("Sentence 2 - I want to put an image on my left"));
messagePanel.add(new Label("Sentence 3- I want to put an image on my left"));
frame.add("North", messagePanel);
frame.add("South", buttonPanel);
frame.pack();
frame.setVisible(true);
     public static void main(String args[])
     new Help();
     public void actionPerformed (ActionEvent a)
          if (a.getActionCommand().equals("Ok"))
               frame.dispose();
}

Hi there,
Here is your program with 3 images on the left and 3 labels on their right. Let me know if you have any questions.
Berk Can Celebisoy
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
public class ForumTest extends Frame implements ActionListener { 
  Button okButton;
  Image image1, image2, image3;
  Toolkit toolkit;
  public ForumTest() {     
     toolkit = Toolkit.getDefaultToolkit();
     image1 = toolkit.getImage("redButton.gif");      
     image2 = toolkit.getImage("greenButton.gif");      
     image3 = toolkit.getImage("blueButton.gif");      
        okButton = new Button ("Ok");     
         okButton.addActionListener (this);     
     ImagePanel imagePanel1 = new ImagePanel(image1);
     ImagePanel imagePanel2 = new ImagePanel(image2);
     ImagePanel imagePanel3 = new ImagePanel(image3);
     Panel buttonPanel = new Panel ();
      buttonPanel.add (okButton);
     Panel messagePanel = new Panel();
      messagePanel.setLayout(new GridLayout(3, 3));
      messagePanel.add(imagePanel1);
      messagePanel.add(new Label("Red button"));
      messagePanel.add(imagePanel2);
      messagePanel.add(new Label("Green button"));
      messagePanel.add(imagePanel3);
      messagePanel.add(new Label("Blue button"));
        this.setLayout(new BorderLayout());     
        this.add("North", messagePanel);
     this.add("South", buttonPanel);     
     this.pack();
     this.setVisible(true);
  public static void main(String args[]) {
    ForumTest forumTest = new ForumTest();
  public void actionPerformed (ActionEvent a) {
    if (a.getActionCommand().equals("Ok"))
      this.dispose();   
class ImagePanel extends Panel {
  Image img;
  ImagePanel(Image img) {
    this.img = img;
  public void paint(Graphics g) {
     g.drawImage(img, 0, 0, this);
}

Similar Messages

  • Could not apply background image to the panel group layout in spaces application

    I tried to apply background image to the panel group layout with css class and also with inline style such as below
    background-image:url('/content/conn/intra-dot-content/path/mywebcenter/lever/backgroundmain.jpg');background-position:center; background-repeat:repeat-y;
    The background image does not show up. but it work with panel border layout. Is there any work around for the issue

    You can try styleclass, which is always better choice than inlinestyle
    page:
    <af:panelGroupLayout id="pgl30"
                                       styleClass="testPGbackground">
                    <af:outputText value="outputText5" id="ot8"/>
                  </af:panelGroupLayout>
    css:
    .testPGbackground {
        background-image:url('/images/unselectedTabStart.png');
    It works for me.
    I tried with inline style also and it worked.
    bac
    <af:panelGroupLayout id="pgl30"
                                       inlineStyle="background-image: url(/incview/images/unselectedTabStart.png);">
                    <af:outputText value="outputText5" id="ot8"/>
                  </af:panelGroupLayout>
    NOTE: You need to mention image url with context-name here, which could be a way of hard coding context name and in future it could be very difficult to change contextname. As recommended styleclass is better solution.
    Thanks
    Sanjeev

  • Creating an image from a panel

    Hi everybody,
    I have a panel which extends JPanel, and wrote an image() method to extract the drawn image off the panel. For some reason, though, when I call this method, I get a dialog with a black box centered in it, and not the appropriate image.
    My SSCCE is as follows:
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import javax.swing.ImageIcon;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.SwingUtilities;
    public class MyPanel extends JPanel {
        private BufferedImage image;
        public BufferedImage image() {
            int x = getWidth();
            int y = getHeight();
            //image = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);
            image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2 = image.createGraphics();
            SwingUtilities.paintComponent( g2, this, new JPanel(), 0, 0, x, y );
            g2.dispose();
            return image;
        public static void main( String args[] ) {
             MyPanel canvas = new MyPanel() {
                  public void paintComponent( Graphics g ) {
                       Graphics2D g2 = (Graphics2D)g;
                       for( int i = 1; i <= 20; i++ ) {
                            int pos = i*50;
                            g2.drawString( "This is a test", pos, pos );
             JDialog test = new JDialog();
            JLabel label = new JLabel( new ImageIcon( canvas.image() ) );
            JScrollPane scroller = new JScrollPane( label );
            scroller.setPreferredSize( new Dimension( 500, 500 ) );
            test.add( scroller );
            test.pack();
            test.setVisible( true );
    }I'm pretty sure it has something to do with the sizing of the image and the timing of the repainting--when I uncomment the commented line in image(), I get an error saying width and height can't be less than or equal to 0. But anyway, I need to paint and then show an image of what was painted, not the actual painted panel--that's what I'm having trouble with. If anyone could help me out, I'd appreciate it. Can anyone help me fix this, please?
    Thanks,
    Jezzica85
    Edited by: jezzica85 on Jun 1, 2009 6:16 AM

    Odd choice to both have the panel with a getImage() method, and also override paintComponent(Graphics).
    Here is an alternate form of your code.
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    public class MyPanel extends JPanel {
      private BufferedImage image;
      public BufferedImage image() {
        int x = 200;
        int y = 200;
        image = new BufferedImage(x,y, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        g2.setColor(Color.yellow);
        g2.fillRect(0,0,x,y);
        g2.setColor(Color.black);
        for( int i = 1; i <= 20; i++ ) {
          int pos = i*50;
          g2.drawString( "This is a test", pos, pos );
        g2.dispose();
        return image;
      public static void main( String args[] ) {
        Runnable r = new Runnable() {
          public void run() {
            MyPanel canvas = new MyPanel();
            JDialog test = new JDialog();
            JLabel label = new JLabel( new ImageIcon( canvas.image() ) );
            JOptionPane.showMessageDialog(null, label);
            JScrollPane scroller = new JScrollPane( label );
            scroller.setPreferredSize( new Dimension( 500, 500 ) );
            JOptionPane.showMessageDialog(null, scroller);
        EventQueue.invokeLater(r);
    }

  • Resizing JFrame on button click to show an image on the JFrame

    Dear All,
    I have a JFrame which has an empty label. On button click I want to set an icon for the label and want the JFrame to be resized to show that icon. I am using frame.pack() and I am not using any other sizing function. The code that I have right now, prints the image on the panel, but does not resize the frame to show the image. Pleae could someone help.package gui;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    public class ComponentDemo extends JPanel implements ActionListener,
    ItemListener, MouseListener, KeyListener {
         private JTextArea textarea;
         private JButton button;
         private final static String newline = "\n";
         private JLabel imageIcon;
         public ComponentDemo() {
              button = new JButton("JButton welcomes you  to CO2001");
              button.addActionListener(this);
              add(button);
              textarea = new JTextArea(10, 50);
              textarea.setEditable(false);
              addMouseListener(this);
              textarea.addKeyListener(this);
              JScrollPane scrollPane = new JScrollPane(textarea);
              add(scrollPane);
              imageIcon = new JLabel();
              add(imageIcon);
              setBackground(Color.pink);
              new JScrollPane(this);
          * Create the GUI and show it. For thread safety, this method should be
          * invoked from the event-dispatching thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("Simple FrameDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              frame.setLocation(700, 200);
              // get the content pane and set the background colour;
              frame.add(new ComponentDemo());
         //     frame.setSize(screenSize);
              // frame.getContentPane().setBackground(Color.cyan);
              // Display the window.
              frame.pack();
              frame.setVisible(true);
              frame.setResizable(true);
         public static void main(String[] args) {
              // Schedule a job for the event-dispatching thread:
              // creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();
         @Override
         public void actionPerformed(ActionEvent e) {
              // TODO Auto-generated method stub
              if (e.getSource() instanceof JButton) {
                   // System.out.println(e.getSource());
                   String text = ((JButton) e.getSource()).getText();
                   textarea.append(text + newline);
                   textarea.setBackground(Color.cyan);
                   textarea.setForeground(Color.BLUE);
                   textarea.setCaretPosition(textarea.getDocument().getLength());
                   imageIcon.setIcon(createImageIcon("SwingingDuke.png",
                   "Image to be displayed"));
         @Override
         public void itemStateChanged(ItemEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mouseClicked(MouseEvent arg0) {
              textarea.append("A Mouse click welcomes you to CO2001" + newline);
              textarea.setBackground(Color.green);
              textarea.setCaretPosition(textarea.getDocument().getLength());
         @Override
         public void mouseEntered(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mouseExited(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mousePressed(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mouseReleased(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void keyPressed(KeyEvent e) {
              System.out.println(e.getKeyChar());
              textarea.append("The key " + e.getKeyChar()
                        + " click welcomes you to CO2001" + newline);
              textarea.setBackground(Color.YELLOW);
              textarea.setFont(new Font("Arial", Font.ITALIC, 16));
              textarea.setCaretPosition(textarea.getDocument().getLength());
         @Override
         public void keyReleased(KeyEvent e) {
              System.out.println(e.getKeyChar());
              // textarea.append("The key "+
              // e.getKeyChar()+" click welcomes you to CO2001" + newline);
              // textarea.setBackground(Color.green);
              // textarea.setCaretPosition(textarea.getDocument().getLength());
         @Override
         public void keyTyped(KeyEvent e) {
              // TODO Auto-generated method stub
              System.out.println(e.getKeyChar());
              // textarea.append("The key "+
              // e.getKeyChar()+" click welcomes you to CO2001" + newline);
              // textarea.setBackground(Color.blue);
              // textarea.setCaretPosition(textarea.getDocument().getLength());
         /** Returns an ImageIcon, or null if the path was invalid. */
         protected ImageIcon createImageIcon(String path, String description) {
              java.net.URL imgURL = getClass().getResource(path);
              if (imgURL != null) {
                   System.out.println("found");
                   return new ImageIcon(imgURL, description);
              } else {
                   System.err.println("Couldn't find file: " + path);
                   return null;
    }

    myJPanel.setPerferredSize(new Dimension(new_width, new_hight));
    myJFrame.pack();

  • Putting an image in a Panel

    i have an applet, i want to put an image in a panel. the image(one image) in the panel will also be changable by button event handling.
    thank you

    You need to follow this steps:
    - Create a class who extends Icon class.
    - Rewrite paintIcon method using tool in Graphics class (drawImage..)
    - Create a JLabel using your cutom icon
    - Insert the JLabel into your panel.
    That's it!

  • Clearing an Image from a panel

    I made an Image object and drew it on a panel using method paintComponent. How can I remove the Image from the panel afterwards?
    Thanks

    Just use the remove method of the JPanel.
    JPanel.remove(imageRefernce);You may also need to call the repaint method as well if it doesn't disapear.

  • Getting the bounds of a drawn image on a panel

    Hello, I have a problem with getting the bounds of a drawn image on a panel...Since it is drawn as graphics, i tried getClipBounds and since my class extends JPanel i tried to get the bounds from the panel but neither of them worked properly. It only gets the bounds of a jframe that contains the panel.Then i tried to put the panel in a layeredpane and then a container; but this time the image disappeared completely. Hope someone can help or tell me what I am doing wrong. Thanks in advance. Here is the code below:
    By the way what I am trying to do in this code is basically zooming the image in and out by dragging or the mouse wheel. But I need to get the bounds so that I can use this.
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    * @author Admin
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.Point;
    import java.awt.RenderingHints;
    import java.awt.Toolkit;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.NoninvertibleTransformException;
    import java.awt.geom.Point2D;
    import javax.swing.JFrame;
    import javax.swing.JLayeredPane;
    import javax.swing.JPanel;
    public class ZoomDemo extends JPanel {
    AffineTransform tx = new AffineTransform();
    String imagePath = "D:/Documents and Settings/Admin/Belgelerim/tsrm/resim.jpg";
    Image image = Toolkit.getDefaultToolkit().getImage(imagePath);
    int width = image.getWidth(this);
    int height = image.getHeight(this);
    int scrwidth = Toolkit.getDefaultToolkit().getScreenSize().width;
    int scrheight = Toolkit.getDefaultToolkit().getScreenSize().height;
    double zoomfac = 1.0;
    int xAdj;
    int yAdj;
    int prevY;
    double scale = 1.0;
    Point pt;
    public static int x;
    public static int y;
    public static int w;
    public static int h;
    public ZoomDemo() {
    this.addMouseWheelListener(new ZoomHandler());
    this.addMouseListener(new ZoomHandler());
    this.addMouseMotionListener(new ZoomHandler());
      repaint();
    @Override
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.drawImage(image, tx, this);
    // x =    (int) g2.getClipBounds().getX();
    // y=     (int) g2.getClipBounds().getY();
    // w=     (int) g2.getClipBounds().getWidth();
    // h=     (int) g2.getClipBounds().getHeight();
    // System.out.println(x+" "+y+" "+w+" "+h);
    //  public int getRectx(){
    //    return x;
    //public int getRecty(){
    //    return y;
    //public int getRectw(){
    //    return w;
    //public int getRecth(){
    //    return h;
    private class ZoomHandler implements MouseWheelListener,MouseListener, MouseMotionListener {
    public void mousePressed(MouseEvent e){
        System.out.println("Mouse Pressed");
    xAdj = e.getX();
    yAdj = e.getY();
    prevY = getY();
    public void mouseDragged(MouseEvent e){
           System.out.println("Mouse Dragged");
    boolean zoomed = false;
    if(e.getY()<prevY){
         zoomfac = zoomfac + 0.1;
         prevY = e.getY();
         zoomed = true;
    else if(e.getY()>prevY){
         zoomfac = zoomfac - 0.1;
         prevY = e.getY();
         zoomed = true;
       scale = zoomfac;
    Point2D p1 = new Point((int)xAdj-(width/2),(int)yAdj-(height/2));
    Point2D p2 = null;
    try {
    p2 = tx.inverseTransform(p1, null);
    } catch (NoninvertibleTransformException ex) {
    // should not get here
    ex.printStackTrace();
    return;
    tx.setToIdentity();
    tx.translate(p1.getX(), p1.getY());
    tx.scale(scale, scale);
    tx.translate(-p2.getX(), -p2.getY());
    tx.transform(p1, p2);
    ZoomDemo.this.revalidate();
    ZoomDemo.this.repaint();
    public void mouseWheelMoved(MouseWheelEvent e) {
    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
    Point2D p1 = e.getPoint();
    Point2D p2 = null;
    try {
    p2 = tx.inverseTransform(p1, null);
    } catch (NoninvertibleTransformException ex) {
    // should not get here
    ex.printStackTrace();
    return;
    scale -= (0.1 * e.getWheelRotation());
    scale = Math.max(0.1, scale);
    tx.setToIdentity();
    tx.translate(p1.getX(), p1.getY());
    tx.scale(scale, scale);
    tx.translate(-p2.getX(), -p2.getY());
    ZoomDemo.this.revalidate();
    ZoomDemo.this.repaint();
            public void mouseClicked(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet.");
            public void mouseReleased(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet.");
            public void mouseEntered(MouseEvent e) {
               // throw new UnsupportedOperationException("Not supported yet.");
            public void mouseExited(MouseEvent e) {
               // throw new UnsupportedOperationException("Not supported yet.");
            public void mouseMoved(MouseEvent e) {
               // throw new UnsupportedOperationException("Not supported yet.");
    public static void main(String[] args) {
    //SwingUtilities.invokeLater(new ZoomDemo());
    int scrwidth = Toolkit.getDefaultToolkit().getScreenSize().width;
    int scrheight = Toolkit.getDefaultToolkit().getScreenSize().height;
    JFrame f = new JFrame("Zoom");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(scrwidth , scrheight);
    //JLayeredPane lp = new JLayeredPane();
    //f.add(lp);
    ZoomDemo zd = new ZoomDemo();
    zd.getBounds();
    f.add(zd);
    //int x = (int) zd.getX();
    //int y = (int) zd.getY();
    //int w = (int) zd.getWidth();
    //int h = (int) zd.getHeight();
    //System.out.println(x+" "+y+" "+w+" "+h);
    //zd.setBounds(x ,y ,w ,h );
    //lp.add(zd, JLayeredPane.DEFAULT_LAYER);
    //f.setLocationRelativeTo(null);
    f.setVisible(true);
    //lp.setVisible(true);
    //zd.setVisible(true);
    }Edited by: .mnemonic. on May 26, 2009 11:07 PM
    Edited by: .mnemonic. on May 27, 2009 11:00 AM

    You'll need a stable point in the component to track and orient to the scaling transform(s).
    From this you can construct whatever you need in the way of image location and size.
    Let's try a center&#8211;of&#8211;image tracking point:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    import javax.swing.event.MouseInputAdapter;
    public class ZD extends JPanel {
        BufferedImage image;
        Point center;
        AffineTransform at = new AffineTransform();
        Point2D.Double origin = new Point2D.Double(0,0);
        public ZD(BufferedImage image) {
            this.image = image;
            center = new Point(image.getWidth()/2, image.getHeight()/2);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            g2.drawRenderedImage(image, at);
            g2.setPaint(Color.red);
            g2.fill(new Ellipse2D.Double(origin.x-1.5, origin.y-1.5, 4, 4));
            g2.setPaint(Color.blue);
            g2.fill(new Ellipse2D.Double(center.x-1.5, center.y-1.5, 4, 4));
        private void setTransform(double scale) {
            // keep image centered over Point "center"
            double x = center.x - scale*image.getWidth()/2;
            double y = center.y - scale*image.getHeight()/2;
            origin.setLocation(x, y);
            at.setToTranslation(x, y);
            at.scale(scale, scale);
        public static void main(String[] args) throws java.io.IOException {
            java.net.URL url = ZD.class.getResource("images/hawk.jpg");
            BufferedImage image = javax.imageio.ImageIO.read(url);
            ZD test = new ZD(image);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(test);
            f.setSize(500,500);
            f.setLocation(100,100);
            f.setVisible(true);
            test.addMouseListener(test.mia);
            test.addMouseMotionListener(test.mia);
        /** MouseAdapter okay in j2se 1.6+ */
        private MouseInputAdapter mia = new MouseInputAdapter() {
            final double SCALE_INC = 0.05;
            final int SCALE_STEP = 20;
            double scale = 1.0;
            double lastStep;
            public void mousePressed(MouseEvent e) {
                Point p = e.getPoint();
                center.setLocation(p);
                //System.out.printf("center = [%3d, %3d]%n", p.x, p.y);
                setTransform(scale);
                repaint();
            public void mouseDragged(MouseEvent e) {
                // scale up/down with relative vertical motion
                int step = (e.getY() - center.y)/SCALE_STEP;
                if(step != lastStep) {
                    scale += SCALE_INC*((step < lastStep) ? -1 : 1);
                    //System.out.printf("step = %3d  scale = %.3f%n", step, scale);
                    setTransform(scale);
                    lastStep = step;
                    repaint();
    }

  • How to remove "Blue filter" from multiple images in the History Panel

    I am using Lightroom 4.3 on Windows 7 pc.  I have a collection with approximately 650 images.  I was working in the collection and had all the images selected.  Somehow I inadvertently must have hit a keyboard shortcut that effected all the images.  All of the images are negatively effected and they now look terrible.  When I go to the History Panel, all the images have "blue filter" as their most recent entry.  If I select one image and go back to the step before the "blue filter" everything looks fine  again.  My problem is I have this effect in 650 images.  When I try and do the change in one image and then synch to the rest, I don't know what box to check to remove this "blue filter" that has been added to all the images.  I know I can do them one by one, but with 650 images, it's a long and tedious process.  Any way I can remove the "blue filter" from multiple images in a collection?
    Thanks,
    Matthew Kraus

    If you’ve just done it, then an Undo operation would reverse things on all the images, I think.  But if it took you a while to see the problem, then you might have done something to cancel the undoability.
    Isn’t Blue Filter a built in LR preset that modifies the HSL settings:  http://kb2.adobe.com/community/publishing/924/cpsid_92473.html
    Open the HSL panel and step back into History on one of the affected images so the effect of the Blue Filter preset has been undone and notice what HSL sliders change, and then if the 650 images DON’T already have any HSL adjustments you should be able to sync JUST the pre-Blue-Filter HSL adjustments (perhaps all zeros) to the other 650 images.

  • Make the panel fit the image so MouseListener only invoke when click  image

    I want to add MouseListener to only the image itself. So I draw the image onto a image panel, add that panel onto the main panel, then add the main panel onto the frame. However, my problem is that the size of my image panel is too large, it take up almost the entire frame. So my mouselistener response not only when I click onto the image, but also anywhere in my image panel. I try to resize the image panel to fit the size of my image, but no luck. Is there a solution for this. I feel like, it got something to do with the layout. Here is my code, if you mind read it. Thank you very much
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import javax.swing.*;
    public class ImageRotate
         private static final String LABEL = "MIDI PROTOCOL";
         private JPanel mainPanel = new JPanel();
         private JPanel labelPanel = new JPanel();
         public ImageRotate()
              mainPanel.setOpaque(true);
              mainPanel.setBackground(Color.YELLOW);
              mainPanel.setLayout(new BorderLayout());
              Font labelFont = new Font("serif", Font.BOLD, 30);
              createLabelPanel(LABEL, labelFont);
              labelPanel.setOpaque(false);
              mainPanel.add(labelPanel, BorderLayout.NORTH);
              Drawing d = new Drawing();
              d.setOpaque(true);
              d.addMouseListener(new MouseAdapter(){
                   public void mousePressed(MouseEvent e)
                        System.out.println("Pressing on the image");
              d.addMouseMotionListener(new MouseAdapter(){
                   public void mouseDragged(MouseEvent e)
                        System.out.println("Dragging the image");
                   public void mouseMoved(MouseEvent e)
              mainPanel.add(d, BorderLayout.CENTER);
         private void createLabelPanel(String str, Font font)
              JLabel label = new JLabel(str);
              label.setFont(font);
              label.setForeground(Color.RED);
              labelPanel.add(label);
         public JPanel getPanel()
              return mainPanel;
         public static void main(String args[])
              JFrame frame = new JFrame();
              frame.getContentPane().add(new ImageRotate().getPanel());
              frame.setSize(new Dimension(300, 300));
              frame.setVisible(true);
    class Drawing extends JPanel
         Image img;
         public Drawing()
              setSize(new Dimension(100,100));     //Try to make the panel fit the image...NO LUCK
              setBackground(Color.GREEN);     
              img = Toolkit.getDefaultToolkit().createImage("images/nob.gif");
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              Graphics2D g2D = (Graphics2D)g;
              g2D.drawImage(img, 40, 40, this);
    }

    yunaeyes wrote:
    In class Drawing extends JPanel, I did try to to set the panel to the image size but no luck there,
    both setSize(new Dimension(100,100)), setPreferredSize(new Dimension(100,100)) does not make the panel smallerIt can be made to work. I find it hard to comment on unseen code.
    >
    BigDaddyLoveHandles wrote:
    I think a better approach is to handle the mouse click properly -- see if the click is over the image or not.Can you elaborate on this?The mousePressed method you posted assumes you are over the image. Check the mouse coordinates! If the component is bigger than the image this may not be so.

  • Cannot separate images from the link panel

    Hi Sir,
    I need advice and tip to ungroup or separate the individual images from the link panel. I cannot select specific image from the rectangle frame. I have screen captured as belew. Any help is greatly appreciated.

    Hi Peter,
    I am using CS6, I managed to select each image using the Direct Selection Tool. However, I noticed that there is a "Link Icon" on the top left corner. Why does it appear?

  • Is it possible to preview images in the files panel?

    sorry in advance for what probably is a dumb question with a
    simple solution.
    i realize i can preview images in the assets panel-- but is
    it possible to preview image files while in the files panel
    instead?
    i have a lot of images organized within folders in the files
    panel-- so it's easier there to locate and visulalize an image--
    than scrolling down the long list in the assets panel.
    thanks.

    Hello,
    I don't believe there is a way to view images in the files
    panel.
    However, there's a quick way to see them if you're using
    Windows.
    Select your image folder in the Files Panel.
    Right click and choose "Explore".
    It opens a window where you can see all the images in that
    folder.
    It's much faster than scrolling through the assets, clicking
    the file names
    and reading the paths to know where they are.
    This is very handy whether you have image folders in
    different directories
    (for organization and cleaner img src paths in the pages
    within the
    directory) or if you just dump them all in a folder in the
    root.
    On my wishlist: Hover over the image name in the files panel
    and a small
    box, like a tool tip, displays the image.
    Maybe someday.
    Take care,
    Tim
    "dexter manika" <[email protected]> wrote in
    message
    news:go4to8$k1m$[email protected]..
    > sorry in advance for what probably is a dumb question
    with a simple
    > solution.
    >
    > i realize i can view images in the assets panel-- but is
    it possible to
    > view
    > image files while in the files panel instead?
    >
    > i have a lot of images organized within folders in the
    files panel-- so
    > it's
    > easier there to locate and visulalize an image-- than
    scrolling down the
    > long
    > list in the assets panel.
    >
    > thanks.
    >

  • Keep rotate image on the top left of my panel.

    Hi,
    Does anyone know how to rotate an image but keep the image to the left upper corner of the panel? I am using affineTransform to perform rotation.
    Thanks.

    What's the problem exactly, does the image move from it's location? Does it not redraw properly? Please be more specific.
    Cheers.

  • Hints image on the animation panel does not change.

    Help I have several animation panels when the program initializes from the constructor. I have a separate AnimationPanel class that creates each panel for display. The initial ?hello ? welcome panel (from the constructor) animates on the main panel when the program begins.
    The problem is I want to have different animation panels (that are stored ) to animate and replace the main panel animation at a push of a button. While, the various panels can animate if called from the constructor, they do not animate when called from a button.
    The buttons I created to switch the main animated panel with a different one seems to work to the extent that it gets the correct music, but the image on the animation panel does not change.
    I know this is a more in depth of a question but might you be able to give me a point in the right direction?
    Here is the code from the constructor that works fine in the constructor to start the main animation.
    public PingPong()
    // null layout because it has a main panel where this display panel is placed
    super(null);
    //panels are created
    instantiatePanels();
    //panels are added to the main content pane
    placePanelsOnView();
    startAnimation();
    initializeAudio();

    The problem is that I now start it with no animation to begin with and just an empty panel, but still when I try to add an animation from the button and it will not start. The contentPane is in a different class that places the buttons and the view together.
    Here is the code that the button calls back with a getNextPanel() :
    AnimatedPanel expertPingPongPlayerPanel
              = new AnimatedPanel( );
    add(expertPingPongPlayerPanel );
         expertPingPongPlayerPanel.animate();
              expertPingPongPlayerPanel.setVisible(true);
              startAnimation();

  • On CS6  with two images in the titles and one open Tutrials tell me that I can drag one onto the greyed title and there will be 2 layers in the layer panel .I have done this many times both with unlocked layers and duplicates . None of three options work.

    In CS^ when I have 2 photos inthe title bar and one is greyed out tutorials tell me I can rag the opened photo onto the greyed title to create two images in the layer panel.  It does not wrk even if I unlock them or use duplicates. Modify keys don,t help.  What is wrong ?

    First select the Move Tool
    Drag the source picture to the tab of the destination picture
    The tab will open to reveal your destination picture, do not release the button yet, but drag the move tool onto the destination picture.
    Then release the mouse button.
    Tell me how you did.
    Gene

  • How can I simultaneously acquire and display an image on the front panel using a PCI-1424

    Dear friends;
    I want to use PCI-1424  , and labview 5.1 to capture the image,  But I can not find some functions in labview to capture, display and save the image.Can you be kind to share some examples or provide some information.
    Another question is how I CAN display the image in the front panel.
    thanks so much

    Hello yangshang,
    Thank you for contacting National Instruments!  To acquire images from the 1424 you will need NI IMAQ 2.5.1 or later.  This can be found HERE on our drivers download page.  One thing to note is that in LabVIEW 5 we only had the ability to view an IMAQ image as a pop up window.  This VI is called "IMAQ Windraw".  This will pop up a separate window that will display your picture.  If you need to view the picture on the front panel you can try saving the image as a file (BMP, JPG, etc) then use the LabVIEW Graphics and Sound VI's to Read a picture file in and then wire the picture to a picture control on the front panel.  Let me know if you have anymore questions.  Good Luck.
    Regards,
    Mark T
    Applications Engineer | National Instruments

Maybe you are looking for

  • Loading One Game Level At a Time

    HI, I have seen in some games where instead of loading the whole game at the beginning of the game, they load one level,  with the preloader on the screen, then when that level is over, another level is loaded, with the preloader on the screen, etc.

  • Bank key/account number

    Hi Experts, I have an issue I have one house bank under house bank i have 3 bank accounts while doing  f-58, i have to select 1 bank out of 3. could you please tell me the solution.

  • Is it possible to have a superdrive on a ibook G4 12" ?

    I'm definetely new to apple but also vary bad with computers...! I want to buy an ibook G4 12" but only if I could have a superdrive on it. I understand that I can't buy it with a superdrive, but is it possible to have someone to put it later? ibook

  • Grey songs on my iPad wont play

    I recently purchased a new computer and downloaded iTunes so that I can sync my iPad to it. I had been running all my music with no problems on my iPad up until now. When I did the first sync with the new iTunes, I went to check my iPad and noticed t

  • Get it right for once

    why con people? this bs of paper free billing having a setting that can be changed, where? there isn't one! yet again you have made a hash up of a fine piece of technology over greed, you have way too many "Pay Now" links but f'all change billing to