🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
6 messages
6 total messages Started by Bruce Houghton Fri, 06 Apr 2007 15:42
Missing events
#243
Author: Bruce Houghton
Date: Fri, 06 Apr 2007 15:42
16 lines
1814 bytes
When using MouseAdapters on JLists or JTables I seem to experience
missing events.  Clicking on an area will always cause that area to be
highlited, but it won't allways cause and event.
One other thing, the Lists and Tables are in ScrollPanes
Q. Is there a better way to do this?
Q. Or is this the only way and I'm stuck with it?
Oh by the way, these are in JApplet's.....JRE1.5...
Bruce Houghton
Example:
JScrollPane jScrollPane = new JScrollPane(jTable1);
jScrollPane.setBounds(new Rectangle(20, 92, 480, 612));
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
   public void mouseClicked(MouseEvent e) {
     JOptionPane.showMessageDialog(null, "Say Something");
   }
}); 
Re: Missing events
#245
Author: Paul Furbacher [TeamB]
Date: Wed, 11 Apr 2007 04:40
40 lines
2186 bytes
Bruce Houghton wrote:

> When using MouseAdapters on JLists or JTables I seem to experience
> missing events.  Clicking on an area will always cause that area to be
> highlited, but it won't allways cause and event.
> One other thing, the Lists and Tables are in ScrollPanes
> Q. Is there a better way to do this?
> Q. Or is this the only way and I'm stuck with it?
> Oh by the way, these are in JApplet's.....JRE1.5...
> Bruce Houghton
> Example:
> JScrollPane jScrollPane = new JScrollPane(jTable1);
> jScrollPane.setBounds(new Rectangle(20, 92, 480, 612));
> jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
>    public void mouseClicked(MouseEvent e) {
>      JOptionPane.showMessageDialog(null, "Say Something");
>    }
> }); 

What are you trying to do? Show an alert just as a test of
clicking?

What's the ultimate desired behavior here?  I can't see
the forest for all the Qs.


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://info.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Re: Missing events
#247
Author: Bruce Houghton
Date: Wed, 11 Apr 2007 21:08
53 lines
2917 bytes
Well, to put it as simply as I can, I created a
JList of names(as in address book). When I click on
a name in the JList, it won't always create an event
even though it does cause that name to be highlighted.

Now, to be more specific, I've build a POS system using
JList's and JTables's. Touching the screen will  always highlight
the field, and a  beeping sound will occure(every time), but
it will not always trigger an event(as in below "Say Something").
Bruce Houghton

"Paul Furbacher [TeamB]" <pfurbacher@mac.com> wrote in message 
news:461c669a$1@newsgroups.borland.com...
> Bruce Houghton wrote:
>
>> When using MouseAdapters on JLists or JTables I seem to experience
>> missing events.  Clicking on an area will always cause that area to be
>> highlited, but it won't allways cause and event.
>> One other thing, the Lists and Tables are in ScrollPanes
>> Q. Is there a better way to do this?
>> Q. Or is this the only way and I'm stuck with it?
>> Oh by the way, these are in JApplet's.....JRE1.5...
>> Bruce Houghton
>> Example:
>> JScrollPane jScrollPane = new JScrollPane(jTable1);
>> jScrollPane.setBounds(new Rectangle(20, 92, 480, 612));
>> jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
>>    public void mouseClicked(MouseEvent e) {
>>      JOptionPane.showMessageDialog(null, "Say Something");
>>    }
>> });
>
> What are you trying to do? Show an alert just as a test of
> clicking?
>
> What's the ultimate desired behavior here?  I can't see
> the forest for all the Qs.
>
>
> -- 
>
>
> Paul Furbacher (TeamB)
>
>   Save time, search the archives:
>        http://info.borland.com/newsgroups/ngsearch.html
>
>   Is it in Joi Ellis's Faq-O-Matic?
>        http://www.visi.com/~gyles19/fom-serve/cache/1.html
>
>   Finally, please send responses to the newsgroup only.
>   That means, do not send email directly to me.
>   Thank you. 
Re: Missing events
#250
Author: Paul Furbacher [TeamB]
Date: Fri, 13 Apr 2007 05:02
138 lines
5470 bytes
Bruce Houghton wrote:

> Well, to put it as simply as I can, I created a
> JList of names(as in address book). When I click on
> a name in the JList, it won't always create an event
> even though it does cause that name to be highlighted.
> 
> Now, to be more specific, I've build a POS system using
> JList's and JTables's. Touching the screen will  always highlight
> the field, and a  beeping sound will occure(every time), but
> it will not always trigger an event(as in below "Say Something").

Does the code below illustrate what you are attempting to do?
If so, see the JavaDoc for JList and the tutorial linked in that
JavaDoc:

   http://java.sun.com/products/jfc/tsc/tech_topics/jlist_1/jlist.html


*****

package bruce.houghton.list.selection;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.BorderLayout;

/**
  * <p>Double-clicking on a list item pops open a message dialog.
  * Single-clicking shows the selected list item in the label below
  * the list.
  * </p>
  */
public class ListEventFrame
     extends JFrame {

   ListModel data = new AbstractListModel() {
        public int getSize() { return Byte.MAX_VALUE; }
        public Object getElementAt(int index) { return "Index " + index; }
    };


   JPanel listPanel = new JPanel();
   JScrollPane scrollPane = new JScrollPane();
   JList listBox = new JList(data);
   GridBagLayout gridBagLayout2 = new GridBagLayout();
   JPanel buttonPanel = new JPanel();
   GridBagLayout gridBagLayout3 = new GridBagLayout();
   JButton quitButton = new JButton();
   BorderLayout borderLayout1 = new BorderLayout();
   JLabel label = new JLabel();

   public ListEventFrame() {
     try {
       jbInit();
     }
     catch (Exception exception) {
       exception.printStackTrace();
     }
   }


   private void jbInit() throws Exception {
     getContentPane().setLayout(gridBagLayout2);
     listPanel.setLayout(borderLayout1);
     buttonPanel.setLayout(gridBagLayout3);
     quitButton.setText("Quit");
     quitButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent actionEvent) {
         quitButton_actionPerformed(actionEvent);
       }
     });
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     scrollPane.setPreferredSize(new Dimension(260, 250));
     listBox.addMouseListener(new MouseAdapter() {
       public void mouseClicked(MouseEvent mouseEvent) {
         listBox_mouseClicked(mouseEvent);
       }
     });
     label.setText("...");
     buttonPanel.add(quitButton, new GridBagConstraints(0, 0, 1, 1, 
0.0, 0.0
         , GridBagConstraints.CENTER, GridBagConstraints.NONE,
         new Insets(0, 0, 0, 0), 0, 0));
     scrollPane.getViewport().add(listBox);
     listPanel.add(scrollPane, java.awt.BorderLayout.CENTER);
     listPanel.add(label, java.awt.BorderLayout.SOUTH);
     this.getContentPane().add(buttonPanel,
                               new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0
         , GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL,
         new Insets(0, 12, 11, 11), 0, 0));
     this.getContentPane().add(listPanel,
                               new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
         , GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
         new Insets(12, 12, 0, 11), 0, 0));
   }

   public static void main(String[] args) {
     ListEventFrame frame = new ListEventFrame();
     frame.pack();
     frame.setVisible(true);
   }

   public void quitButton_actionPerformed(ActionEvent actionEvent) {
     System.exit(0);
   }

   public void listBox_mouseClicked(MouseEvent mouseEvent) {
     int index = listBox.locationToIndex(mouseEvent.getPoint());
     String str = (String)listBox.getModel().getElementAt(index);
     System.out.println("Double clicked on Item " + index);
     if (mouseEvent.getClickCount() == 2) {
       JOptionPane.showMessageDialog(this, str);
       return;
     }
     if ( mouseEvent.getClickCount() == 1 ) {
       label.setText(str);
     }
   }

}


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://info.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Re: Missing events
#251
Author: Bruce Houghton
Date: Fri, 13 Apr 2007 17:59
150 lines
6330 bytes
Thanks Paul, I've given up on the MouseAdapter and have
implemented the "ListSelectionListener". I lose a little
functionality(Right Mouse Button), but I am now
guaranteed an "Event".
It's one of those things, the customer was happy with
the behavior of the Mouse(1 in 10 failures), but when
they moved to POS Touch Screens, the lost event's were
just unacceptable.
Bruce Houghton

"Paul Furbacher [TeamB]" <pfurbacher@mac.com> wrote in message 
news:461f0edd$1@newsgroups.borland.com...
> Bruce Houghton wrote:
>
>> Well, to put it as simply as I can, I created a
>> JList of names(as in address book). When I click on
>> a name in the JList, it won't always create an event
>> even though it does cause that name to be highlighted.
>>
>> Now, to be more specific, I've build a POS system using
>> JList's and JTables's. Touching the screen will  always highlight
>> the field, and a  beeping sound will occure(every time), but
>> it will not always trigger an event(as in below "Say Something").
>
> Does the code below illustrate what you are attempting to do?
> If so, see the JavaDoc for JList and the tutorial linked in that
> JavaDoc:
>
>   http://java.sun.com/products/jfc/tsc/tech_topics/jlist_1/jlist.html
>
>
> *****
>
> package bruce.houghton.list.selection;
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
> import java.awt.BorderLayout;
>
> /**
>  * <p>Double-clicking on a list item pops open a message dialog.
>  * Single-clicking shows the selected list item in the label below
>  * the list.
>  * </p>
>  */
> public class ListEventFrame
>     extends JFrame {
>
>   ListModel data = new AbstractListModel() {
>        public int getSize() { return Byte.MAX_VALUE; }
>        public Object getElementAt(int index) { return "Index " + index; }
>    };
>
>
>   JPanel listPanel = new JPanel();
>   JScrollPane scrollPane = new JScrollPane();
>   JList listBox = new JList(data);
>   GridBagLayout gridBagLayout2 = new GridBagLayout();
>   JPanel buttonPanel = new JPanel();
>   GridBagLayout gridBagLayout3 = new GridBagLayout();
>   JButton quitButton = new JButton();
>   BorderLayout borderLayout1 = new BorderLayout();
>   JLabel label = new JLabel();
>
>   public ListEventFrame() {
>     try {
>       jbInit();
>     }
>     catch (Exception exception) {
>       exception.printStackTrace();
>     }
>   }
>
>
>   private void jbInit() throws Exception {
>     getContentPane().setLayout(gridBagLayout2);
>     listPanel.setLayout(borderLayout1);
>     buttonPanel.setLayout(gridBagLayout3);
>     quitButton.setText("Quit");
>     quitButton.addActionListener(new ActionListener() {
>       public void actionPerformed(ActionEvent actionEvent) {
>         quitButton_actionPerformed(actionEvent);
>       }
>     });
>     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>     scrollPane.setPreferredSize(new Dimension(260, 250));
>     listBox.addMouseListener(new MouseAdapter() {
>       public void mouseClicked(MouseEvent mouseEvent) {
>         listBox_mouseClicked(mouseEvent);
>       }
>     });
>     label.setText("...");
>     buttonPanel.add(quitButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 
> 0.0
>         , GridBagConstraints.CENTER, GridBagConstraints.NONE,
>         new Insets(0, 0, 0, 0), 0, 0));
>     scrollPane.getViewport().add(listBox);
>     listPanel.add(scrollPane, java.awt.BorderLayout.CENTER);
>     listPanel.add(label, java.awt.BorderLayout.SOUTH);
>     this.getContentPane().add(buttonPanel,
>                               new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0
>         , GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL,
>         new Insets(0, 12, 11, 11), 0, 0));
>     this.getContentPane().add(listPanel,
>                               new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
>         , GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
>         new Insets(12, 12, 0, 11), 0, 0));
>   }
>
>   public static void main(String[] args) {
>     ListEventFrame frame = new ListEventFrame();
>     frame.pack();
>     frame.setVisible(true);
>   }
>
>   public void quitButton_actionPerformed(ActionEvent actionEvent) {
>     System.exit(0);
>   }
>
>   public void listBox_mouseClicked(MouseEvent mouseEvent) {
>     int index = listBox.locationToIndex(mouseEvent.getPoint());
>     String str = (String)listBox.getModel().getElementAt(index);
>     System.out.println("Double clicked on Item " + index);
>     if (mouseEvent.getClickCount() == 2) {
>       JOptionPane.showMessageDialog(this, str);
>       return;
>     }
>     if ( mouseEvent.getClickCount() == 1 ) {
>       label.setText(str);
>     }
>   }
>
> }
>
>
> -- 
>
>
> Paul Furbacher (TeamB)
>
>   Save time, search the archives:
>        http://info.borland.com/newsgroups/ngsearch.html
>
>   Is it in Joi Ellis's Faq-O-Matic?
>        http://www.visi.com/~gyles19/fom-serve/cache/1.html
>
>   Finally, please send responses to the newsgroup only.
>   That means, do not send email directly to me.
>   Thank you. 
Re: Missing events
#256
Author: garethconner
Date: Tue, 29 May 2007 01:59
24 lines
2196 bytes
On Apr 6, 11:42 am, "Bruce Houghton" <bhou...@globalserve.net> wrote:
> When using MouseAdapters on JLists or JTables I seem to experience
> missing events.  Clicking on an area will always cause that area to be
> highlited, but it won't allways cause and event.
> One other thing, the Lists and Tables are in ScrollPanes
> Q. Is there a better way to do this?
> Q. Or is this the only way and I'm stuck with it?
> Oh by the way, these are in JApplet's.....JRE1.5...
> Bruce Houghton
> Example:
> JScrollPane jScrollPane = new JScrollPane(jTable1);
> jScrollPane.setBounds(new Rectangle(20, 92, 480, 612));
> jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
>    public void mouseClicked(MouseEvent e) {
>      JOptionPane.showMessageDialog(null, "Say Something");
>    }
>
> });

It's more reliable to use mousePressed(MouseEvent e).  The
mouseClicked event will only be dispatched if the cursor position
hasn't changed between the mousePressed and mouseReleased.

-Gareth Conner
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads