How to remove scrollbar from java.awt.Choice?

A

anywherenotes

Hi,

We have an application that shows month selection using
java.awt.Choice
Client complained that they get a scrollbar, and they would prefer to
just have all the choices available without having to scroll. Since
it's only 12 choices it seems reasonable, but I'm not sure how to
accomplish it.
Currently only 8 choices show up, and for the rest you have to scroll.

Thank you in advance.
Alex
 
M

Mark Space

Hi,

We have an application that shows month selection using
java.awt.Choice
Client complained that they get a scrollbar, and they would prefer to
just have all the choices available without having to scroll. Since
it's only 12 choices it seems reasonable, but I'm not sure how to
accomplish it.
Currently only 8 choices show up, and for the rest you have to scroll.

Thank you in advance.
Alex

I don't see any options relating to scrolling for the Choice component.
Use a List maybe?
 
A

Andrew Thompson

On Dec 10, 5:19 am, (e-mail address removed) wrote:
....
We have an application that shows month selection using
java.awt.Choice

Why? Or more pointedly, why is this GUI
coded in AWT rather than Swing, in this
day and age?
 
A

anywherenotes

On Dec 10, 5:19 am, (e-mail address removed) wrote:
...


Why?  Or more pointedly, why is this GUI
coded in AWT rather than Swing, in this
day and age?

The application overall is about 15 years old, I'm not sure when this
client was written, but it's printing code has been there since java
1.1 and is currently assuming either Java 1.2 or 1.3 behavior, can't
remember.

Is it possible to accomplish what I described in swing?
I haven't done much GUI programming, please let me know which class to
look into.

I'd like to not recode the entire window, and for sure I cannot recode
this whole client, but changing from say java.awt.Choice to
javax.swing.something should be fine.
 
A

anywherenotes

     For what it's worth, I've tried a few combinations: putting a
Choice with twelve month names in a Frame or in a JFrame, using
different layout managers, and so on.  On *none* of them did I get
any scroll bars!  The only way I could get scroll bars to show up
was to add more items to the Choice: twenty-four didn't scroll,
but thirty-six did.

    My suspicion at the moment is that there's something else you're
doing that causes the Choice to behave this way: Setting a size on
the Container or on the Choice itself, using a layout manager that
I didn't try, using a gigantic font, or something of that sort.  But
without knowing just what you're doing, all I can do is guess.

     Could you whittle down your code to a short, complete, compilable
example that demonstrates the problem, and post it?  Exact details
on the Java version would also be welcome.

Thank you for looking into it.
I noticed that if I run the same application on a different machine I
do not get a scrollbar, however I am getting it on my machine, and
apparently our client is too.

The program below reproduces the issue, though it's not based on our
code, but rather just a sample code I found online while trying to see
if the issue was with our application or somewhere else. On one
machine the pulldown Choice doesn't have a scrollbar, and on the other
machine it does.
The machine where I do not get the scrollbar has java 1.6.0_10
The machine where I do get the scrollbar has java 1.6.0_05

/* copied from
** http://java.comsci.us/examples/awt/Choice.html
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;

public class Choice2 extends JFrame implements ItemListener {
/* Declaration */
private LayoutManager Layout;
private Choice Selector;
private Font SansSerif;

public static void main(String []argv)
{
Choice2 c2 = new Choice2();
}

public Choice2 () {
/* Declaration */
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String [] ColorList;
int i;

/* Instantiation */
ColorList = new String [20];
SansSerif = new Font ("SansSerif", Font.BOLD, 14);
Layout = new FlowLayout ();
Selector = new Choice ();

/* Decoration */
ColorList [0] = "Red";
ColorList [1] = "Magenta";
ColorList [2] = "Blue";
ColorList [3] = "Cyan";
ColorList [4] = "Green";
ColorList [5] = "Yellow";
ColorList [6] = "White";
ColorList [7] = "Gray";
ColorList [8] = "Black";
ColorList [9] = "Black2";
ColorList [10] = "1Red";
ColorList [11] = "1Magenta";
ColorList [12] = "1Blue";
ColorList [13] = "1Cyan";
ColorList [14] = "1Green";
ColorList [15] = "1Yellow";
ColorList [16] = "1White";
ColorList [17] = "1Gray";
ColorList [18] = "1Black";
ColorList [19] = "1Black2";
for (i = 0; i < ColorList.length; ++i) {
Selector.insert (ColorList , i);
}
Selector.setBackground (Color.yellow);
Selector.setForeground (Color.red);
Selector.setFont (SansSerif);

/* Location */
setLayout (Layout);
add (Selector);

/* Configuration */
Selector.addItemListener (this);

/* Initialization */
Selector.select (5);
setBackground (Color.yellow);

setSize(300, 300);
setVisible(true);
}

public void itemStateChanged(ItemEvent e) {
int Selection;
Selection = Selector.getSelectedIndex();
if (Selection == 0) {
setBackground (Color.red);
} else if (Selection == 1) {
setBackground (Color.magenta);
} else if (Selection == 2) {
setBackground (Color.blue);
} else if (Selection == 3) {
setBackground (Color.cyan);
} else if (Selection == 4) {
setBackground (Color.green);
} else if (Selection == 5) {
setBackground (Color.yellow);
} else if (Selection == 6) {
setBackground (Color.white);
} else if (Selection == 7) {
setBackground (Color.gray);
} else if (Selection == 8) {
setBackground (Color.black);
}
}

}
 
A

anywherenotes

[... unwanted scroll bars on Choice displays ...]
Thank you for looking into it.
I noticed that if I run the same application on a different machine I
do not get a scrollbar, however I am getting it on my machine, and
apparently our client is too.
The program below reproduces the issue, though it's not based on our
code, but rather just a sample code I found online while trying to see
if the issue was with our application or somewhere else.  On one
machine the pulldown Choice doesn't have a scrollbar, and on the other
machine it does.
The machine where I do not get the scrollbar has java 1.6.0_10
The machine where I do get the scrollbar has java 1.6.0_05
[... bletcherous code snipped ...]

     One obvious thing to check is the Java version: Try running
1.6.0_10 on the problematic system and see if the behavior changes.
For what it's worth, I'm running 1.6.0_11 and see no scroll bars
when I run your sample code.  (Not even when I blow the font up
to 96 pixels; the expanded Choice pulldown no longer fits on my
screen, but doesn't scroll.)

     If the two machines exhibit different behavior even with the
same Java version, then you'll need to start looking at other
differences between them.  Screen size and resolution, display
settings, fonts, O/S versions, ...  Sorry I can't be of more
help, but the problem doesn't seem to be directly caused by the
code you've shown.  Good luck!

I tried running with 1.6.0_10 on my machine (where I am getting the
scroll bar), and got the scroll bar. It's probably reasonable to
assume it's a machine setting, as I also checked for same resolution,
font size, etc.
Just can't find where the issue lies, but likely not a java issue.

Is there another 'choice' that I can use which gives me control over
the scrollbar?
 
J

John B. Matthews

[... unwanted scroll bars on Choice displays ...]
I tried running with 1.6.0_10 on my machine (where I am getting the
scroll bar), and got the scroll bar. It's probably reasonable to
assume it's a machine setting, as I also checked for same resolution,
font size, etc.
Just can't find where the issue lies, but likely not a java issue.
[...]

On Mac OS 10.5, Java 1.5, activating the Choice2 pop-up displays a
scrollable menu of several color names with a triangle indicating more
choices. Initially, the triangle is above, yellow is selected, and 16.3
choices are shown. Navigating up with mouse or keyboard shows the full
20. On subsequent displays, the list is scrolled to show the last choice.

Could this be a Look-and-Feel-specific setting?
 
J

jlp

(e-mail address removed) a écrit :
[... unwanted scroll bars on Choice displays ...]
Thank you for looking into it.
I noticed that if I run the same application on a different machine I
do not get a scrollbar, however I am getting it on my machine, and
apparently our client is too.
The program below reproduces the issue, though it's not based on our
code, but rather just a sample code I found online while trying to see
if the issue was with our application or somewhere else. On one
machine the pulldown Choice doesn't have a scrollbar, and on the other
machine it does.
The machine where I do not get the scrollbar has java 1.6.0_10
The machine where I do get the scrollbar has java 1.6.0_05
[... bletcherous code snipped ...]
One obvious thing to check is the Java version: Try running
1.6.0_10 on the problematic system and see if the behavior changes.
For what it's worth, I'm running 1.6.0_11 and see no scroll bars
when I run your sample code. (Not even when I blow the font up
to 96 pixels; the expanded Choice pulldown no longer fits on my
screen, but doesn't scroll.)

If the two machines exhibit different behavior even with the
same Java version, then you'll need to start looking at other
differences between them. Screen size and resolution, display
settings, fonts, O/S versions, ... Sorry I can't be of more
help, but the problem doesn't seem to be directly caused by the
code you've shown. Good luck!

I tried running with 1.6.0_10 on my machine (where I am getting the
scroll bar), and got the scroll bar. It's probably reasonable to
assume it's a machine setting, as I also checked for same resolution,
font size, etc.
Just can't find where the issue lies, but likely not a java issue.

Is there another 'choice' that I can use which gives me control over
the scrollbar?
If OS=Windows, try with desabling Direct3D => -Dsun.java2d.d3d=false
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top