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;
What OS are you using and what version of Tk::JComboBox do you have?
-Ken
This may be a bug. As a workaround, you could add this right after
creating the JComboBox:
$jcb->setSelected($variable);
> 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
> 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
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