🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #251

Re: Missing events

#251
From: 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. 
Technical Details
Message-ID: <461fc4ce$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder2.cambrium.nl!feed.tweaknews.nl!news.astraweb.com!newsrouter-eu.astraweb.com!newsfeed2.ip.tiscali.net!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <46166a31$1@newsgroups.borland.com> <461c669a$1@newsgroups.borland.com> <461d4e22@newsgroups.borland.com> <461f0edd$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,dec980017feb87ab
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Bruce Houghton" <bhought@globalserve.net>
From: "Bruce Houghton" <bhought@globalserve.net>
Newsgroups: borland.public.jbuilder.java.swing
References: <46166a31$1@newsgroups.borland.com> <461c669a$1@newsgroups.borland.com> <461d4e22@newsgroups.borland.com> <461f0edd$1@newsgroups.borland.com>
Subject: Re: Missing events
Date: Fri, 13 Apr 2007 13:59:24 -0400
Lines: 152
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 207.112.55.146
Message-ID: <461fc4ce$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1176487118 207.112.55.146 (13 Apr 2007 10:58:38 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder2.cambrium.nl!feed.tweaknews.nl!news.astraweb.com!newsrouter-eu.astraweb.com!newsfeed2.ip.tiscali.net!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail