Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tk::JComboBox Question

24 views
Skip to first unread message

Fun...@hello.net

unread,
Oct 19, 2005, 10:20:54 AM10/19/05
to
I have a question about the Tk::JComboBox package. When I run the
script below and click the down arrow to display the drop down list,
the default item ($variable) is NOT selected or hilighted in the list.
If I click anywhere else to make the list go away and then click the
down arrow again to redisplay the list, then the default item
($variable) IS selected and displayed in the list. Why is it NOT
selected and displayed the first time? Thanks for your help.

Here is a sample script:

#!/usr/bin/perl

use strict;
use Tk;
use Tk::JComboBox;

my $variable = "11";
my @choices = ();
my $x = 1;
while ($x < 21)
{
my $y = $x;
if (length($y) < 2)
{
$y = " " . $y;
}
push @choices, $y;
$x++;
}

my $mw = MainWindow->new;
my $jcb = $mw -> JComboBox (
-mode => 'readonly',
-relief => 'groove',
-textvariable => \$variable,
-choices => \@choices)
-> pack (
-side => 'left');
MainLoop;

x3v0-...@yahoo.com

unread,
Oct 19, 2005, 3:13:29 PM10/19/05
to
Strange, when I run your script "11" is already selected. I tested this
on linux.

What OS are you using and what version of Tk::JComboBox do you have?

-Ken

x3v0-...@yahoo.com

unread,
Oct 19, 2005, 3:19:33 PM10/19/05
to
Sorry, I didn't fully understand your post before replying. I now
understand what you mean, and I get the same behavior as you do.

This may be a bug. As a workaround, you could add this right after
creating the JComboBox:

$jcb->setSelected($variable);

Rob Seegel

unread,
Oct 19, 2005, 8:44:47 PM10/19/05
to
Fun...@hello.net wrote:

> I have a question about the Tk::JComboBox package. When I run the
> script below and click the down arrow to display the drop down list,
> the default item ($variable) is NOT selected or hilighted in the list.
> If I click anywhere else to make the list go away and then click the
> down arrow again to redisplay the list, then the default item
> ($variable) IS selected and displayed in the list. Why is it NOT
> selected and displayed the first time? Thanks for your help.

Thanks for the bug report, I'm working on a fix. The suggested
workaround is a good one. I should have have a fix for it soon.

Rob

Rob Seegel

unread,
Oct 19, 2005, 10:32:16 PM10/19/05
to
Rob Seegel wrote:

> Fun...@hello.net wrote:
>
>> I have a question about the Tk::JComboBox package. When I run the
>> script below and click the down arrow to display the drop down list,
>> the default item ($variable) is NOT selected or hilighted in the list.
>> If I click anywhere else to make the list go away and then click the
>> down arrow again to redisplay the list, then the default item
>> ($variable) IS selected and displayed in the list. Why is it NOT
>> selected and displayed the first time? Thanks for your help.
>
>
> Thanks for the bug report, I'm working on a fix. The suggested
> workaround is a good one. I should have have a fix for it soon.
>

Ok... I have a possible fix for it, but I'm going to need another day or
so to test it, to ensure that it doesn't have any unintended
consequences. I'll post a follow-up at then time. I actually wish that I
hadn't made -textvariable a JComboBox option, it's something that I've
found to be problematic sometimes, and a reason why I've provided other
ways of getting the selection. Anyway, look for another release with the
fix by the end of this week. Thanks again.

Rob

Rob Seegel

unread,
Oct 23, 2005, 6:24:45 PM10/23/05
to
Rob Seegel wrote:
> Ok... I have a possible fix for it, but I'm going to need another day or
> so to test it, to ensure that it doesn't have any unintended
> consequences. I'll post a follow-up at then time. I actually wish that I
> hadn't made -textvariable a JComboBox option, it's something that I've
> found to be problematic sometimes, and a reason why I've provided other
> ways of getting the selection. Anyway, look for another release with the
> fix by the end of this week. Thanks again.

For anyone who might have been following this thread. I've released a
new version of JComboBox in CPAN, and created an announcement that has
details of the change in the ptk mailing list (which will be propagated
to c.l.p.tk eventually). It was posted under the subject: [ANNOUNCE]
Tk-JComboBox 1.10

Rob

0 new messages