Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34083 > unrolled thread

Scrollable Popup Menu Keyboard Navigation

Started byEric Douglas <e.d.programmer@gmail.com>
First post2016-04-07 12:21 -0700
Last post2016-06-07 16:58 +0000
Articles 20 — 5 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Scrollable Popup Menu Keyboard Navigation Eric Douglas <e.d.programmer@gmail.com> - 2016-04-07 12:21 -0700
    Re: Scrollable Popup Menu Keyboard Navigation Jeff Higgins <jeff@invalid.invalid> - 2016-04-08 00:12 +0000
      Re: Scrollable Popup Menu Keyboard Navigation Eric Douglas <e.d.programmer@gmail.com> - 2016-04-08 04:29 -0700
        Re: Scrollable Popup Menu Keyboard Navigation Jeff Higgins <jeff@invalid.invalid> - 2016-04-08 15:27 +0000
          Re: Scrollable Popup Menu Keyboard Navigation Eric Douglas <e.d.programmer@gmail.com> - 2016-04-08 08:52 -0700
            Re: Scrollable Popup Menu Keyboard Navigation Jeff Higgins <jeff@invalid.invalid> - 2016-04-08 16:31 +0000
              Re: Scrollable Popup Menu Keyboard Navigation Eric Douglas <e.d.programmer@gmail.com> - 2016-04-08 11:07 -0700
                Re: Scrollable Popup Menu Keyboard Navigation Jeff Higgins <jeff@invalid.invalid> - 2016-04-08 20:39 +0000
                  Re: Scrollable Popup Menu Keyboard Navigation Eric Douglas <e.d.programmer@gmail.com> - 2016-04-08 14:00 -0700
                    Re: Scrollable Popup Menu Keyboard Navigation Jeff Higgins <jeff@invalid.invalid> - 2016-04-08 21:43 +0000
                      Re: Scrollable Popup Menu Keyboard Navigation Jeff Higgins <jeff@invalid.invalid> - 2016-04-09 11:46 +0000
                    Re: Scrollable Popup Menu Keyboard Navigation Jeff Higgins <jeff@invalid.invalid> - 2016-04-08 22:33 +0000
                    Re: Scrollable Popup Menu Keyboard Navigation Robert Klemme <shortcutter@googlemail.com> - 2016-04-10 11:20 +0200
            Re: Scrollable Popup Menu Keyboard Navigation Robert Klemme <shortcutter@googlemail.com> - 2016-04-10 11:20 +0200
              Re: Scrollable Popup Menu Keyboard Navigation Eric Douglas <e.d.programmer@gmail.com> - 2016-04-11 05:00 -0700
    Re: Scrollable Popup Menu Keyboard Navigation Jeff Higgins <jeff@invalid.invalid> - 2016-04-08 23:09 +0000
      Re: Scrollable Popup Menu Keyboard Navigation Eric Douglas <e.d.programmer@gmail.com> - 2016-04-11 05:13 -0700
      Re: Scrollable Popup Menu Keyboard Navigation Fredrik Jonson <fredrik@jonson.org> - 2016-04-18 08:50 +0000
        Re: Scrollable Popup Menu Keyboard Navigation Eric Douglas <e.d.programmer@gmail.com> - 2016-04-18 05:00 -0700
    Re: Scrollable Popup Menu Keyboard Navigation Martin Gregorie <martin@address-in-sig.invalid> - 2016-06-07 16:58 +0000

#34083 — Scrollable Popup Menu Keyboard Navigation

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-04-07 12:21 -0700
SubjectScrollable Popup Menu Keyboard Navigation
Message-ID<dfd94962-3cdc-4cf0-a142-2ccd54c2bb41@googlegroups.com>
Below is some runnable code of my scrollable popup menu, I think about as simple as I can get it.  I did write a hack with the key map to make page-up and page-down work.  I'm just wondering if I'm missing something.  Am I supposed to have to manually tell it what to do when someone presses page-up, page-down, home, end?  Why does just the up and down arrow keys work by default?  This also allows the down arrow to select menu items you can't see, so I also wrote a hack to keep the current item visible.


public class TestClass1 {

     public static void main(final String[] args) {

          EventQueue.invokeLater(new Runnable() {

               @Override
               public void run() {
                    final int maximumVisibleRows = 5;
                    final JFrame win = new JFrame();
                    final JScrollBar myScroll = new JScrollBar();
                    final JPopupMenu myMenu = new JPopupMenu() {

                         {
                              setLayout(new ScrollPopupMenuLayout());
                              add(myScroll);
                         }

                         @Override
                         public void show(final Component invoker, final int x, final int y) {
                              if (invoker instanceof JTextComponent && !(invoker.isFocusOwner())) {
                                   invoker.requestFocusInWindow();

                              }
                              if (myScroll.isVisible()) {
                                   int extent = 0;
                                   int max = 0;
                                   int i = 0;
                                   int unit = -1;
                                   int width = 0;
                                   for (final Component comp : getComponents()) {
                                        if (!(comp instanceof JScrollBar)) {
                                             final Dimension preferredSize = comp.getPreferredSize();
                                             width = Math.max(width, preferredSize.width);
                                             if (unit < 0) {
                                                  unit = preferredSize.height;
                                             }
                                             if (i++ < maximumVisibleRows) {
                                                  extent += preferredSize.height;
                                             }
                                             max += preferredSize.height;
                                        }
                                   }

                                   final Insets insets = getInsets();
                                   final int widthMargin = insets.left + insets.right;
                                   final int heightMargin = insets.top + insets.bottom;
                                   myScroll.setUnitIncrement(unit);
                                   myScroll.setBlockIncrement(extent);
                                   myScroll.setValues(0, heightMargin + extent, 0, heightMargin + max);

                                   width += myScroll.getPreferredSize().width + widthMargin;
                                   final int height = heightMargin + extent;

                                   setPopupSize(new Dimension(width, height));
                              }

                              super.show(invoker, x, y);
                         }
                    };
                    myMenu.add(new JMenuItem("A"));
                    myMenu.add(new JMenuItem("B"));
                    myMenu.add(new JMenuItem("C"));
                    myMenu.add(new JMenuItem("D"));
                    myMenu.add(new JMenuItem("E"));
                    myMenu.add(new JMenuItem("F"));
                    myMenu.add(new JMenuItem("G"));
                    win.addMouseListener(new MouseAdapter() {

                         @Override
                         public void mousePressed(final MouseEvent e) {
                              checkPopup(e);
                         }

                         @Override
                         public void mouseClicked(final MouseEvent e) {
                              checkPopup(e);
                         }

                         @Override
                         public void mouseReleased(final MouseEvent e) {
                              checkPopup(e);
                         }

                         private void checkPopup(final MouseEvent e) {
                              if (e.isPopupTrigger()) {
                                   myMenu.show(win, e.getX(), e.getY());
                              }
                         }
                    });
                    win.setSize(200, 120);
                    win.setVisible(true);
               }

          });
     }

     protected static class ScrollPopupMenuLayout implements LayoutManager, Serializable {

          @Override
          public void addLayoutComponent(final String name, final Component comp) {
          }

          @Override
          public void removeLayoutComponent(final Component comp) {
          }

          @Override
          public Dimension preferredLayoutSize(final Container parent) {
               int visibleAmount = Integer.MAX_VALUE;
               final Dimension dim = new Dimension();
               for (final Component comp : parent.getComponents()) {
                    if (comp.isVisible()) {
                         if (comp instanceof JScrollBar) {
                              final JScrollBar scrollBar = (JScrollBar) comp;
                              visibleAmount = scrollBar.getVisibleAmount();
                         } else {
                              final Dimension pref = comp.getPreferredSize();
                              dim.width = Math.max(dim.width, pref.width);
                              dim.height += pref.height;
                         }
                    }
               }

               final Insets insets = parent.getInsets();
               dim.height = Math.min(dim.height + insets.top + insets.bottom, visibleAmount);

               return dim;
          }

          @Override
          public Dimension minimumLayoutSize(final Container parent) {
               int visibleAmount = Integer.MAX_VALUE;
               final Dimension dim = new Dimension();
               for (final Component comp : parent.getComponents()) {
                    if (comp.isVisible()) {
                         if (comp instanceof JScrollBar) {
                              final JScrollBar scrollBar = (JScrollBar) comp;
                              visibleAmount = scrollBar.getVisibleAmount();
                         } else {
                              final Dimension min = comp.getMinimumSize();
                              dim.width = Math.max(dim.width, min.width);
                              dim.height += min.height;
                         }
                    }
               }

               final Insets insets = parent.getInsets();
               dim.height = Math.min(dim.height + insets.top + insets.bottom, visibleAmount);

               return dim;
          }

          @Override
          public void layoutContainer(final Container parent) {
               final Insets insets = parent.getInsets();

               int width = parent.getWidth() - insets.left - insets.right;
               final int height = parent.getHeight() - insets.top - insets.bottom;

               final int x = insets.left;
               int y = insets.top;
               int position = 0;

               for (final Component comp : parent.getComponents()) {
                    if ((comp instanceof JScrollBar) && comp.isVisible()) {
                         final JScrollBar scrollBar = (JScrollBar) comp;
                         final Dimension dim = scrollBar.getPreferredSize();
                         scrollBar.setBounds(x + width - dim.width, y, dim.width, height);
                         width -= dim.width;
                         position = scrollBar.getValue();
                    }
               }

               y -= position;
               for (final Component comp : parent.getComponents()) {
                    if (!(comp instanceof JScrollBar) && comp.isVisible()) {
                         final Dimension pref = comp.getPreferredSize();
                         comp.setBounds(x, y, width, pref.height);
                         y += pref.height;
                    }
               }
          }
     }
}

[toc] | [next] | [standalone]


#34085

FromJeff Higgins <jeff@invalid.invalid>
Date2016-04-08 00:12 +0000
Message-ID<ne6t1i$q9d$1@dont-email.me>
In reply to#34083
On Thu, 07 Apr 2016 12:21:32 -0700, Eric Douglas wrote:

> Below is some runnable code of my scrollable popup menu, I think about
> as simple as I can get it.  I did write a hack with the key map to make
> page-up and page-down work.  I'm just wondering if I'm missing
> something.  Am I supposed to have to manually tell it what to do when
> someone presses page-up, page-down, home, end?  Why does just the up and
> down arrow keys work by default?  This also allows the down arrow to
> select menu items you can't see, so I also wrote a hack to keep the
> current item visible.
> 
Have you looked at How to Use Key Bindings in the Java Tutorials?

[toc] | [prev] | [next] | [standalone]


#34089

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-04-08 04:29 -0700
Message-ID<12b619c7-c6ba-4eb6-a064-e0b992b0c785@googlegroups.com>
In reply to#34085
On Thursday, April 7, 2016 at 8:16:04 PM UTC-4, Jeff Higgins wrote:
> Have you looked at How to Use Key Bindings in the Java Tutorials?

Was that part not clear?  The key map is the key bindings.  I said I wrote the maps to make page-up and page-down work.  I'm just wondering if I'm missing something.  Why do I have to manually write logic for all other navigation keys but I didn't write anything for up and down arrow keys and those work?

[toc] | [prev] | [next] | [standalone]


#34090

FromJeff Higgins <jeff@invalid.invalid>
Date2016-04-08 15:27 +0000
Message-ID<ne8il1$v2$1@dont-email.me>
In reply to#34089
On Fri, 08 Apr 2016 04:29:55 -0700, Eric Douglas wrote:

> On Thursday, April 7, 2016 at 8:16:04 PM UTC-4, Jeff Higgins wrote:
>> Have you looked at How to Use Key Bindings in the Java Tutorials?
> 
> Was that part not clear?  The key map is the key bindings.  I said I
> wrote the maps to make page-up and page-down work.  I'm just wondering
> if I'm missing something.  Why do I have to manually write logic for all
> other navigation keys but I didn't write anything for up and down arrow
> keys and those work?

Your entire original post was somewhat unclear, which may explain the
lack of responses other than mine - which you've dismissed. The use case
for a scrollable pop-up menu is, for me, unclear - but there seems to be
quite a bit of activity around it on the WWW. Searching "java+scrollable
+pop-up+menu" I find quite a few examples - none of which involve a 
custom layout manager.

[toc] | [prev] | [next] | [standalone]


#34091

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-04-08 08:52 -0700
Message-ID<b5b0a40b-6f31-4055-a923-832c47944f2c@googlegroups.com>
In reply to#34090
On Friday, April 8, 2016 at 11:31:00 AM UTC-4, Jeff Higgins wrote:
> Your entire original post was somewhat unclear, which may explain the
> lack of responses other than mine - which you've dismissed. The use case
> for a scrollable pop-up menu is, for me, unclear - but there seems to be
> quite a bit of activity around it on the WWW. Searching "java+scrollable
> +pop-up+menu" I find quite a few examples - none of which involve a 
> custom layout manager.

What's unclear about that?  It's a runnable self contained sample that displays a window.  Right click the window and you get a popup menu.  I'm asking why that popup menu can navigate by default using up and down arrow keys I didn't write anything special for, but I have to write key map code to manually tell it what to do if I want page-up and page-down to work.

Why do the up and down arrow automatically work?  Am I missing something to make the page-up and page-down work automatically?  Is there a better way to write a scrollable popup menu entirely that has keyboard navigation built in and/or looks cleaner?

If you Google that class you'll see I didn't come up with the layout manager.  I threw it in the example because it didn't look right without it.  It appears I copied that code from here:
https://stackoverflow.com/questions/9288350/adding-vertical-scroll-to-a-jpopupmenu

[toc] | [prev] | [next] | [standalone]


#34092

FromJeff Higgins <jeff@invalid.invalid>
Date2016-04-08 16:31 +0000
Message-ID<ne8mcu$dhg$1@dont-email.me>
In reply to#34091
On Fri, 08 Apr 2016 08:52:07 -0700, Eric Douglas wrote:

> On Friday, April 8, 2016 at 11:31:00 AM UTC-4, Jeff Higgins wrote:
>> Your entire original post was somewhat unclear, which may explain the
>> lack of responses other than mine - which you've dismissed. The use
>> case for a scrollable pop-up menu is, for me, unclear - but there seems
>> to be quite a bit of activity around it on the WWW. Searching
>> "java+scrollable +pop-up+menu" I find quite a few examples - none of
>> which involve a custom layout manager.
> 
> What's unclear about that?  It's a runnable self contained sample that
> displays a window.  Right click the window and you get a popup menu. 
> I'm asking why that popup menu can navigate by default using up and down
> arrow keys I didn't write anything special for, but I have to write key
> map code to manually tell it what to do if I want page-up and page-down
> to work.
> 
> Why do the up and down arrow automatically work?  Am I missing something
> to make the page-up and page-down work automatically?  Is there a better
> way to write a scrollable popup menu entirely that has keyboard
> navigation built in and/or looks cleaner?
> 
> If you Google that class you'll see I didn't come up with the layout
> manager.  I threw it in the example because it didn't look right without
> it.  It appears I copied that code from here:
> https://stackoverflow.com/questions/9288350/adding-vertical-scroll-to-a-
jpopupmenu

I'd suggest examining the code and documentation of the classes that you
are attempting to make use of to gain an understanding of how they work
and why they work as they do rather than relying on cut/paste cargo cult
programming. What does home, end, pgup, pgdn, left, right, up, down mean
to a generic scrollbar? A generic menu? How are those ideas implemented
or not in the classes you are attempting to use? What should they mean in
your scrollbar, menu?

[toc] | [prev] | [next] | [standalone]


#34093

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-04-08 11:07 -0700
Message-ID<7aec131f-7f4f-4ff3-a565-9eb327ea7c18@googlegroups.com>
In reply to#34092
On Friday, April 8, 2016 at 12:34:53 PM UTC-4, Jeff Higgins wrote:
> I'd suggest examining the code and documentation of the classes that you
> are attempting to make use of to gain an understanding of how they work
> and why they work as they do rather than relying on cut/paste cargo cult
> programming. What does home, end, pgup, pgdn, left, right, up, down mean
> to a generic scrollbar? A generic menu? How are those ideas implemented
> or not in the classes you are attempting to use? What should they mean in
> your scrollbar, menu?

The cut and pasting is irrelevant.  I understand the code I pasted, I know it doesn't have anything in it to tell the control what to do on a down arrow keypress.  Do you have answers or are you just here to criticize?  A forum is useless if you're just going to make people sorry they bothered to ask a question.
Is the scroll bar object telling the popup menu object to scroll down one menu item on a down arrow keypress?  Why then does it tell it to do nothing on page down?  Are you pointing me to answers or repeating my questions?

[toc] | [prev] | [next] | [standalone]


#34094

FromJeff Higgins <jeff@invalid.invalid>
Date2016-04-08 20:39 +0000
Message-ID<ne94t4$dhg$2@dont-email.me>
In reply to#34093
On Fri, 08 Apr 2016 11:07:51 -0700, Eric Douglas wrote:

> On Friday, April 8, 2016 at 12:34:53 PM UTC-4, Jeff Higgins wrote:
>> I'd suggest examining the code and documentation of the classes that
>> you are attempting to make use of to gain an understanding of how they
>> work and why they work as they do rather than relying on cut/paste
>> cargo cult programming. What does home, end, pgup, pgdn, left, right,
>> up, down mean to a generic scrollbar? A generic menu? How are those
>> ideas implemented or not in the classes you are attempting to use? What
>> should they mean in your scrollbar, menu?
> 
> The cut and pasting is irrelevant.  I understand the code I pasted, I
> know it doesn't have anything in it to tell the control what to do on a
> down arrow keypress.

You may well understand the code you posted. You obviously don't 
understand the code that others have written and that you are attempting
to use. If a down arrow keypress does indeed have an affect then it is in
the code and may even be documented. It is in your interest to understand
the code you are using.

> Do you have answers or are you just here to
> criticize?  A forum is useless if you're just going to make people sorry
> they bothered to ask a question.

I've asked a lot of questions on c.l.j.p and got some good answers and
some not so good. I have also answered a lot of questions here, some of
my answers may have been better than others. Does my suggestion, that you
read the code, documentation, and tutorials make you feel sorry that you
bothered to ask the question? Do you really want me to read the relevant
code, documentation, and tutorials for you?

> Is the scroll bar object telling the popup menu object to scroll down
> one menu item on a down arrow keypress?

What do the code, documentation and tutorials say?

> Why then does it tell it to do
> nothing on page down?

The code and documentation may not be explicit here. Ask the author.

> Are you pointing me to answers or repeating my
> questions?

I hope that I am pointing a way forward.

[toc] | [prev] | [next] | [standalone]


#34095

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-04-08 14:00 -0700
Message-ID<f5a09310-1f76-4209-a7b9-6ce97b5ec032@googlegroups.com>
In reply to#34094
On Friday, April 8, 2016 at 4:42:28 PM UTC-4, Jeff Higgins wrote:
> I hope that I am pointing a way forward.

Hmm, nope, you're condescending.  Not a single link to which documentation you're referring.  Should I read the entire internet?  The entire Oracle doc?  Which particular class, javadoc, book are you talking about?  Is there a book sitting in front of you I'm supposed to be reading?  Answering a question with a generic "read the documentation" is just going to make someone mad.  I'm thinking if this is the only response I can get here, it tells me nothing, I shouldn't ask questions here.  If you really think a specific answer to my question is in some documentation (online??) post a link to the specific page/text you're talking about, otherwise no response is better than a lame one.

[toc] | [prev] | [next] | [standalone]


#34096

FromJeff Higgins <jeff@invalid.invalid>
Date2016-04-08 21:43 +0000
Message-ID<ne98lt$dhg$3@dont-email.me>
In reply to#34095
On Fri, 08 Apr 2016 14:00:18 -0700, Eric Douglas wrote:

> On Friday, April 8, 2016 at 4:42:28 PM UTC-4, Jeff Higgins wrote:
>> I hope that I am pointing a way forward.
> 
> Hmm, nope, you're condescending.  Not a single link to which
> documentation you're referring.  Should I read the entire internet?  The
> entire Oracle doc?  Which particular class, javadoc, book are you
> talking about?  Is there a book sitting in front of you I'm supposed to
> be reading?  Answering a question with a generic "read the
> documentation" is just going to make someone mad.  I'm thinking if this
> is the only response I can get here, it tells me nothing, I shouldn't
> ask questions here.  If you really think a specific answer to my
> question is in some documentation (online??) post a link to the specific
> page/text you're talking about, otherwise no response is better than a
> lame one.

Code
<http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/
classes/javax/swing>

Documentation
<http://docs.oracle.com/javase/8/docs/api/javax/swing/package-
summary.html>
<http://docs.oracle.com/javase/8/docs/api/javax/swing/plaf/package-
summary.html>
<http://docs.oracle.com/javase/8/docs/api/javax/swing/plaf/basic/package-
summary.html>

Tutorial
<http://docs.oracle.com/javase/tutorial/uiswing/index.html>

Just for giggles.

/**
 * Any component that can be placed into a menu should implement this 
interface.
 * This interface is used by <code>MenuSelectionManager</code>
 * to handle selection and navigation in menu hierarchies.
 *
 * @author Arnaud Weber
 */
public interface MenuElement

I hope you react to suggestion better in person than you do online.

[toc] | [prev] | [next] | [standalone]


#34100

FromJeff Higgins <jeff@invalid.invalid>
Date2016-04-09 11:46 +0000
Message-ID<neaq2b$a24$1@dont-email.me>
In reply to#34096
This might also be helpful for someone down the road.

Keyboard Bindings in Swing

This document provides a review of the existing key binding facilities 
in Swing and defines a new set of APIs that unify what we have today 
and satisfy the requirements listed in the next section.

Hans Muller and Scott Violet Last modified: Fri Jun 4 13:00:54 PDT 1999

<http://www.comp.nus.edu.sg/~cs3283/ftp/Java/swingConnect/special_report/kestrel/keybindings.html>

[toc] | [prev] | [next] | [standalone]


#34097

FromJeff Higgins <jeff@invalid.invalid>
Date2016-04-08 22:33 +0000
Message-ID<ne9bjp$dhg$4@dont-email.me>
In reply to#34095
On Fri, 08 Apr 2016 14:00:18 -0700, Eric Douglas wrote:

> On Friday, April 8, 2016 at 4:42:28 PM UTC-4, Jeff Higgins wrote:
>> I hope that I am pointing a way forward.
> 
> Hmm, nope, you're condescending.  Not a single link to which
> documentation you're referring.  Should I read the entire internet?  The
> entire Oracle doc?  Which particular class, javadoc, book are you
> talking about?  Is there a book sitting in front of you I'm supposed to
> be reading?  Answering a question with a generic "read the
> documentation" is just going to make someone mad.  I'm thinking if this
> is the only response I can get here, it tells me nothing, I shouldn't
> ask questions here.  If you really think a specific answer to my
> question is in some documentation (online??) post a link to the specific
> page/text you're talking about, otherwise no response is better than a
> lame one.

Likewise, no request for assistance is better than a lame one.

How To Ask Questions The Smart Way
<http://catb.org/~esr/faqs/smart-questions.html>

[toc] | [prev] | [next] | [standalone]


#34101

FromRobert Klemme <shortcutter@googlemail.com>
Date2016-04-10 11:20 +0200
Message-ID<dmuk7mFjmt7U1@mid.individual.net>
In reply to#34095
On 08.04.2016 23:00, Eric Douglas wrote:
> On Friday, April 8, 2016 at 4:42:28 PM UTC-4, Jeff Higgins wrote:
>> I hope that I am pointing a way forward.
>
> Hmm, nope, you're condescending.

While that may be the way you perceive it I suggest to be careful with 
these types of attributions.  There is way too much lost in electronic 
communication and you cannot look into other people's heads either. 
Jeff did at least bother to answer, that is probably not as 
condescending as it may seem to you.

Regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

[toc] | [prev] | [next] | [standalone]


#34102

FromRobert Klemme <shortcutter@googlemail.com>
Date2016-04-10 11:20 +0200
Message-ID<dmuk7qFjmtnU1@mid.individual.net>
In reply to#34091
On 08.04.2016 17:52, Eric Douglas wrote:

> I'm asking why that popup menu can navigate by default using
> up and down arrow keys I didn't write anything special for, but I
> have to write key map code to manually tell it what to do if I want
> page-up and page-down to work.

I assume it is because there is no universal concept of "page 
scrolling".  If you look closer scrolling page wise is a much more 
complex topic than scrolling individual items.  For example, some 
applications will not show anything that has been shown before a "page 
down" while others will show some amount of the last content (e.g. to 
improve reading experience).  Then, do you measure "page" in terms of 
fixed size units or fixed entries?  With the former you might get half 
shown entries at the top if the window height is not an exact multiple 
of the item height while with the latter you always start at an item 
boundary.

Regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

[toc] | [prev] | [next] | [standalone]


#34104

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-04-11 05:00 -0700
Message-ID<5507be2a-93e2-4131-bf96-b562b34713a1@googlegroups.com>
In reply to#34102
On Sunday, April 10, 2016 at 5:21:08 AM UTC-4, Robert Klemme wrote:
> I assume it is because there is no universal concept of "page 
> scrolling".  If you look closer scrolling page wise is a much more 
> complex topic than scrolling individual items.  For example, some 
> applications will not show anything that has been shown before a "page 
> down" while others will show some amount of the last content (e.g. to 
> improve reading experience).  Then, do you measure "page" in terms of 
> fixed size units or fixed entries?  With the former you might get half 
> shown entries at the top if the window height is not an exact multiple 
> of the item height while with the latter you always start at an item 
> boundary.

No universal concept, then why is it univerally implemented?  If I press page down in any web browser or text editor it scrolls down, typically by the amount of one visible area.  If that's not good enough they could add a method to set the amount you'd want to scroll down but that ought to be the default.  Meanwhile they did implement the arrow up and down which somehow moved the bar by the height of a menu item, which could just as well have moved it one pixel at a time.  How is one universal and not the other?

[toc] | [prev] | [next] | [standalone]


#34099

FromJeff Higgins <jeff@invalid.invalid>
Date2016-04-08 23:09 +0000
Message-ID<ne9dn0$dhg$5@dont-email.me>
In reply to#34083
Just as an aside. Most of the long menus that I run into, including Pan,
the newsreader I'm using now, and Eclipse IDE, use something similar to 
that demonstrated here:

<https://tips4java.wordpress.com/2009/02/01/menu-scroller/>

rather than a scrollbar.

I'm not sure I've ever seen a menu with a scrollbar.

[toc] | [prev] | [next] | [standalone]


#34106

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-04-11 05:13 -0700
Message-ID<585e1060-0af1-440f-a9f0-048d35da2f5f@googlegroups.com>
In reply to#34099
On Friday, April 8, 2016 at 7:12:50 PM UTC-4, Jeff Higgins wrote:
> Just as an aside. Most of the long menus that I run into, including Pan,
> the newsreader I'm using now, and Eclipse IDE, use something similar to 
> that demonstrated here:
> 
> <https://tips4java.wordpress.com/2009/02/01/menu-scroller/>
> 
> rather than a scrollbar.
> 
> I'm not sure I've ever seen a menu with a scrollbar.

I did come across that example, using up and down arrows in the space of first and last visible menu item, which I didn't think made as much sense as a scrollbar but thanks, at least you came up with some responses which look like you're trying to be helpful.  Pardon me if I read something wrong but your first couple responses sound like "how dare you ask that?" like it's about basics of a language that no one should be writing Java without knowing.

I was just wondering if there is a method I was missing to make page up and page down just work, without having to map key bindings for each with a custom action that calls the methods to get the scroll bar's visible height and calculate it's new index, or if this should be implemented using JScrollPane instead.

[toc] | [prev] | [next] | [standalone]


#34161

FromFredrik Jonson <fredrik@jonson.org>
Date2016-04-18 08:50 +0000
Message-ID<slrnnh97uu.nb7.fredrik@biggles.jonson.org>
In reply to#34099
In <ne9dn0$dhg$5@dont-email.me> Jeff Higgins wrote:

>  Just as an aside. Most of the long menus that I run into, including Pan,
>  the newsreader I'm using now, and Eclipse IDE, use [a menu scroller]

And aside from that from that I recommend that you should avoid making menus
that are so long that the user have to scroll. Scrolled menus hinders the user
from seeing all options and scrolling in a menu is hard because if the
user happens to focus outside the menu it will dissapear and the user will
have to repeat his navigation.

Instead, try to find a way to divide the menu into several menus, or open
a dialog from a main menu item, and let the user choose his option from a
list in that dialog. Or even better, try to reduce the total number of
menu items, too many is an indication of poor usability and design.

-- 
Fredrik Jonson

[toc] | [prev] | [next] | [standalone]


#34165

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-04-18 05:00 -0700
Message-ID<a8ab05c8-f592-489a-a003-105e2f61a3e8@googlegroups.com>
In reply to#34161
On Monday, April 18, 2016 at 4:50:48 AM UTC-4, Fredrik Jonson wrote:
> And aside from that from that I recommend that you should avoid making menus
> that are so long that the user have to scroll. Scrolled menus hinders the user
> from seeing all options and scrolling in a menu is hard because if the
> user happens to focus outside the menu it will dissapear and the user will
> have to repeat his navigation.

It's not a menu, it's a popup.  I have a JButton next to an input with a down arrow image.  Select it and it creates a JPopupMenu, populated with all possible values for that field.  This may not really be a lot of values, perhaps just 20, but we still don't want to take up half the screen so we set a max 10 values visible at one time.

[toc] | [prev] | [next] | [standalone]


#34539

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2016-06-07 16:58 +0000
Message-ID<nj6ufv$t5i$1@dont-email.me>
In reply to#34083
On Thu, 07 Apr 2016 12:21:32 -0700, Eric Douglas wrote:

> Below is some runnable code of my scrollable popup menu, I think about
> as simple as I can get it.  I did write a hack with the key map to make
> page-up and page-down work.  I'm just wondering if I'm missing
> something.  Am I supposed to have to manually tell it what to do when
> someone presses page-up, page-down, home, end?  Why does just the up and
> down arrow keys work by default?  This also allows the down arrow to
> select menu items you can't see, so I also wrote a hack to keep the
> current item visible.
>
Yep, it compiles OK once I added some imports, and some bits work, but 
there is one omission and one rather obvious problem:

- the Jframe doesn't call setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
  which makes your code annoying to run.

- the scrollable menu doesn't. The scrollbar zonks up and down without
  affecting the visible menu items and the up and down arrows happily
  disappear off the bottom of the menu without scrolling anything up.

Both of which rather defeat your stated purpose in devising this 
structure. Or did you fix this later but not post it?


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web