Displaying an image and capturing mouse clicks doesn't work at the same time“cannot find symbol method drawImage(java.awt.image.BufferedImage,<nulltype>,int,int)”Why can't I draw an ellipse with this code?how to perform mouse on click action using threadsDrag and Drop nodes in JTreeJScrollPane adding JPanels at the top and keeping current scroll viewadd KeyListener to JLabelError when trying to update a picture in JPanelJPanel added but not displayed “in time”Drawing an image in JScrollPane within scaleJComboBox mistake with repaint() method

How can a Lich look like a human without magic?

When a land becomes a creature, is it untapped?

Why do Thanos's punches not kill Captain America or at least cause some mortal injuries?

Smallest Guaranteed hash collision cycle length

Can I make ravioli dough with only all-purpose flour or do I NEED semolina flour?

Run script for 10 times until meets the condition, but break the loop if it meets the condition during iteration

What's special about a Bunsen burner?

Speculative Biology of a Haplodiploid Humanoid Species

What are the implications of the new alleged key recovery attack preprint on SIMON?

Proof that the inverse image of a single element is a discrete space

Why does my circuit work on a breadboard, but not on a perfboard? I am new to soldering

What is Plautus’s pun about frustum and frustrum?

Word for being out at night during curfew

Setting the major mode of a new buffer interactively

Why can't RGB or bicolour LEDs produce a decent yellow?

On studying Computer Science vs. Software Engineering to become a proficient coder

Extrude the faces of a cube symmetrically along XYZ

How can I answer high-school writing prompts without sounding weird and fake?

Do atomic orbitals "pulse" in time?

Why does getw return -1 when trying to read a character?

Why in a Ethernet LAN, a packet sniffer can obtain all packets sent over the LAN?

Can the sorting of a list be verified without comparing neighbors?

Was there ever any real use for a 6800-based Apple I?

Understanding integration over Orthogonal Group



Displaying an image and capturing mouse clicks doesn't work at the same time


“cannot find symbol method drawImage(java.awt.image.BufferedImage,<nulltype>,int,int)”Why can't I draw an ellipse with this code?how to perform mouse on click action using threadsDrag and Drop nodes in JTreeJScrollPane adding JPanels at the top and keeping current scroll viewadd KeyListener to JLabelError when trying to update a picture in JPanelJPanel added but not displayed “in time”Drawing an image in JScrollPane within scaleJComboBox mistake with repaint() method






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















What I want to do:



I want to write a small application that can display an image. The user has to be able to zoom in and out of the image, move it around, and mark points on the image. Further down the line I want to analyze the points clicked, but I'm not there yet.



What I have so far:



In order to track down my problem I wrote a MVCE:



GUI class for handling the JFrame (and other UI elements later):



import javax.swing.*;
import java.net.MalformedURLException;
import java.net.URL;

public class MCVE_GUI

public static void main(String[] args) throws MalformedURLException
MCVE_ZoomPane zp = new MCVE_ZoomPane(new URL("https://fiji.sc/site/logo.png"));

JFrame f = new JFrame("PictureMeasurement");
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
f.setContentPane(zp);
f.pack();
f.setLocationRelativeTo(null);
f.revalidate();
f.repaint();
f.setVisible(true);





ZoomPanel for handling the image and zooming:



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;

class MCVE_ZoomPane extends JPanel implements MouseMotionListener

MCVE_ZoomPane(URL url)
JLabel image = new JLabel();
JScrollPane jsp = new JScrollPane(image);

//image.setIcon(new ImageIcon(url)); // picture, no input
//jsp.setPreferredSize(new Dimension(300,300)); //picture, no input
jsp.setPreferredSize(image.getPreferredSize()); //depends on position of image.setIcon
image.setIcon(new ImageIcon(url)); //no picture, input

this.add(jsp);
this.setPreferredSize(image.getPreferredSize());
this.addMouseMotionListener(this);


@Override
public void paintComponent(Graphics g)
super.paintComponent(g);


public void mouseDragged(MouseEvent e)
System.out.format("Dragged X:%d Y:%dn",e.getX(), e.getY());


public void mouseMoved(MouseEvent e)




The problem:



Depending on where I put the image.setIcon(new ImageIcon(url)) I get either the image displayed or can listen to mouse clicks, but not both together. If I set the JScrollPane to a fixed preferred size without calling image.getPreferredSize() I always get a picture but no input.










share|improve this question




























    0















    What I want to do:



    I want to write a small application that can display an image. The user has to be able to zoom in and out of the image, move it around, and mark points on the image. Further down the line I want to analyze the points clicked, but I'm not there yet.



    What I have so far:



    In order to track down my problem I wrote a MVCE:



    GUI class for handling the JFrame (and other UI elements later):



    import javax.swing.*;
    import java.net.MalformedURLException;
    import java.net.URL;

    public class MCVE_GUI

    public static void main(String[] args) throws MalformedURLException
    MCVE_ZoomPane zp = new MCVE_ZoomPane(new URL("https://fiji.sc/site/logo.png"));

    JFrame f = new JFrame("PictureMeasurement");
    f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    f.setContentPane(zp);
    f.pack();
    f.setLocationRelativeTo(null);
    f.revalidate();
    f.repaint();
    f.setVisible(true);





    ZoomPanel for handling the image and zooming:



    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.URL;

    class MCVE_ZoomPane extends JPanel implements MouseMotionListener

    MCVE_ZoomPane(URL url)
    JLabel image = new JLabel();
    JScrollPane jsp = new JScrollPane(image);

    //image.setIcon(new ImageIcon(url)); // picture, no input
    //jsp.setPreferredSize(new Dimension(300,300)); //picture, no input
    jsp.setPreferredSize(image.getPreferredSize()); //depends on position of image.setIcon
    image.setIcon(new ImageIcon(url)); //no picture, input

    this.add(jsp);
    this.setPreferredSize(image.getPreferredSize());
    this.addMouseMotionListener(this);


    @Override
    public void paintComponent(Graphics g)
    super.paintComponent(g);


    public void mouseDragged(MouseEvent e)
    System.out.format("Dragged X:%d Y:%dn",e.getX(), e.getY());


    public void mouseMoved(MouseEvent e)




    The problem:



    Depending on where I put the image.setIcon(new ImageIcon(url)) I get either the image displayed or can listen to mouse clicks, but not both together. If I set the JScrollPane to a fixed preferred size without calling image.getPreferredSize() I always get a picture but no input.










    share|improve this question
























      0












      0








      0








      What I want to do:



      I want to write a small application that can display an image. The user has to be able to zoom in and out of the image, move it around, and mark points on the image. Further down the line I want to analyze the points clicked, but I'm not there yet.



      What I have so far:



      In order to track down my problem I wrote a MVCE:



      GUI class for handling the JFrame (and other UI elements later):



      import javax.swing.*;
      import java.net.MalformedURLException;
      import java.net.URL;

      public class MCVE_GUI

      public static void main(String[] args) throws MalformedURLException
      MCVE_ZoomPane zp = new MCVE_ZoomPane(new URL("https://fiji.sc/site/logo.png"));

      JFrame f = new JFrame("PictureMeasurement");
      f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      f.setContentPane(zp);
      f.pack();
      f.setLocationRelativeTo(null);
      f.revalidate();
      f.repaint();
      f.setVisible(true);





      ZoomPanel for handling the image and zooming:



      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.net.URL;

      class MCVE_ZoomPane extends JPanel implements MouseMotionListener

      MCVE_ZoomPane(URL url)
      JLabel image = new JLabel();
      JScrollPane jsp = new JScrollPane(image);

      //image.setIcon(new ImageIcon(url)); // picture, no input
      //jsp.setPreferredSize(new Dimension(300,300)); //picture, no input
      jsp.setPreferredSize(image.getPreferredSize()); //depends on position of image.setIcon
      image.setIcon(new ImageIcon(url)); //no picture, input

      this.add(jsp);
      this.setPreferredSize(image.getPreferredSize());
      this.addMouseMotionListener(this);


      @Override
      public void paintComponent(Graphics g)
      super.paintComponent(g);


      public void mouseDragged(MouseEvent e)
      System.out.format("Dragged X:%d Y:%dn",e.getX(), e.getY());


      public void mouseMoved(MouseEvent e)




      The problem:



      Depending on where I put the image.setIcon(new ImageIcon(url)) I get either the image displayed or can listen to mouse clicks, but not both together. If I set the JScrollPane to a fixed preferred size without calling image.getPreferredSize() I always get a picture but no input.










      share|improve this question














      What I want to do:



      I want to write a small application that can display an image. The user has to be able to zoom in and out of the image, move it around, and mark points on the image. Further down the line I want to analyze the points clicked, but I'm not there yet.



      What I have so far:



      In order to track down my problem I wrote a MVCE:



      GUI class for handling the JFrame (and other UI elements later):



      import javax.swing.*;
      import java.net.MalformedURLException;
      import java.net.URL;

      public class MCVE_GUI

      public static void main(String[] args) throws MalformedURLException
      MCVE_ZoomPane zp = new MCVE_ZoomPane(new URL("https://fiji.sc/site/logo.png"));

      JFrame f = new JFrame("PictureMeasurement");
      f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      f.setContentPane(zp);
      f.pack();
      f.setLocationRelativeTo(null);
      f.revalidate();
      f.repaint();
      f.setVisible(true);





      ZoomPanel for handling the image and zooming:



      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.net.URL;

      class MCVE_ZoomPane extends JPanel implements MouseMotionListener

      MCVE_ZoomPane(URL url)
      JLabel image = new JLabel();
      JScrollPane jsp = new JScrollPane(image);

      //image.setIcon(new ImageIcon(url)); // picture, no input
      //jsp.setPreferredSize(new Dimension(300,300)); //picture, no input
      jsp.setPreferredSize(image.getPreferredSize()); //depends on position of image.setIcon
      image.setIcon(new ImageIcon(url)); //no picture, input

      this.add(jsp);
      this.setPreferredSize(image.getPreferredSize());
      this.addMouseMotionListener(this);


      @Override
      public void paintComponent(Graphics g)
      super.paintComponent(g);


      public void mouseDragged(MouseEvent e)
      System.out.format("Dragged X:%d Y:%dn",e.getX(), e.getY());


      public void mouseMoved(MouseEvent e)




      The problem:



      Depending on where I put the image.setIcon(new ImageIcon(url)) I get either the image displayed or can listen to mouse clicks, but not both together. If I set the JScrollPane to a fixed preferred size without calling image.getPreferredSize() I always get a picture but no input.







      java image swing interactive






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 11:56









      Turun ambartanenTurun ambartanen

      115




      115






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Apparently I'm stupid. The JScrollPane/JLabel covered the JPanel which was the only component which had a MouseMotionListener. The solution is to add the single line of image.addMouseMotionListener(this);.



          I thought about and tried different soltuions to this for at least three hours now. It's a hobby project, so no time constaints, but man do I feel stupid now.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55313480%2fdisplaying-an-image-and-capturing-mouse-clicks-doesnt-work-at-the-same-time%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Apparently I'm stupid. The JScrollPane/JLabel covered the JPanel which was the only component which had a MouseMotionListener. The solution is to add the single line of image.addMouseMotionListener(this);.



            I thought about and tried different soltuions to this for at least three hours now. It's a hobby project, so no time constaints, but man do I feel stupid now.






            share|improve this answer



























              0














              Apparently I'm stupid. The JScrollPane/JLabel covered the JPanel which was the only component which had a MouseMotionListener. The solution is to add the single line of image.addMouseMotionListener(this);.



              I thought about and tried different soltuions to this for at least three hours now. It's a hobby project, so no time constaints, but man do I feel stupid now.






              share|improve this answer

























                0












                0








                0







                Apparently I'm stupid. The JScrollPane/JLabel covered the JPanel which was the only component which had a MouseMotionListener. The solution is to add the single line of image.addMouseMotionListener(this);.



                I thought about and tried different soltuions to this for at least three hours now. It's a hobby project, so no time constaints, but man do I feel stupid now.






                share|improve this answer













                Apparently I'm stupid. The JScrollPane/JLabel covered the JPanel which was the only component which had a MouseMotionListener. The solution is to add the single line of image.addMouseMotionListener(this);.



                I thought about and tried different soltuions to this for at least three hours now. It's a hobby project, so no time constaints, but man do I feel stupid now.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 23 at 12:00









                Turun ambartanenTurun ambartanen

                115




                115





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55313480%2fdisplaying-an-image-and-capturing-mouse-clicks-doesnt-work-at-the-same-time%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현