Results 1 to 7 of 7
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default JButton plus Icon, but run into a action listener's problem

    So I managed to substitute some standard JButtons by some nice Icons: great!
    But now I run into a action-listener's problem.
    Here is the relevant code:

    Java Code:
    FW = new JButton();
          //      FW.setPreferredSize(new Dimension(65, 30));
                FW.setBorder(BorderFactory.createEmptyBorder());
                FW.setContentAreaFilled(false);
                FWicon = createButtonIcon("FW.jpg");
                FW.setIcon(FWicon);
            //    FW.setActionCommand("FW");
    The way I'd like to get the action command of the particular button:
    (here is where is goes wrong?)

    Java Code:
    private class ButtonDialog implements ActionListener { // button listener
    
           public void actionPerformed(ActionEvent e) {
    
              
                if (e.getSource() == FW) {
                    imagecount++;
                    if (imagecount >= maximages) imagecount = 0;
    
                    DS.getSlideImage( imagefiles.get(imagecount)) ;
                    repaint();
                } etc....

  2. #2
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: JButton plus Icon, but run into a action listener's problem

    I see it myself now: there is no actionlistener added, right?

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: JButton plus Icon, but run into a action listener's problem

    Anyway, now being here again I have an other question:
    My applet draws a thin lined marker a rectangle that shows the border.
    How to get rid of that thin rectangle?

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: JButton plus Icon, but run into a action listener's problem

    button.setFocusPainted(false);

  5. #5
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Re: JButton plus Icon, but run into a action listener's problem

    I mean the thin line that the applet generates see here:

    JButton plus Icon, but run into a action listener's problem-applet-line.png
    Last edited by willemjav; 04-27-2013 at 10:37 PM.

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: JButton plus Icon, but run into a action listener's problem

    I've never seen an applet to that. Post a Short, Self Contained, Correct Example that demonstrates your problem.

  7. #7
    sevoxx is offline Oracle Java Developer
    Join Date
    Apr 2013
    Location
    In a PineApple Under the Sea
    Posts
    20
    Rep Power
    0

    Default Re: JButton plus Icon, but run into a action listener's problem

    This has absolutely nothing to do with the ActionListener. RTFM.

Similar Threads

  1. Replies: 1
    Last Post: 01-15-2013, 07:44 PM
  2. Replies: 2
    Last Post: 12-11-2011, 11:44 PM
  3. Replies: 2
    Last Post: 11-09-2011, 07:24 PM
  4. Replies: 10
    Last Post: 04-03-2011, 12:06 AM
  5. Problem in action listener
    By cool in forum AWT / Swing
    Replies: 4
    Last Post: 11-16-2010, 08:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •