I'm having a little trouble with JComboBox for Tk. I am using ActiveState perl version 5.6.1 and JComboBox version .02 or at least I think it's version .02 on a win2k box. Here's the scenario:

I have a window for used for searching a database with widgets used for selecting a subset of criteria and one of these widgets is a JComboBox. The same window also contains a button that will bring up a dialog used to define the whole set of search criteria. The dialog also includes a JComboBox widget that is linked to the same data as the first JComboBox I mentioned.

The problem is that when I change the value of the JComboBox in the dialog, it makes the first JComboBox drop down it's list. Subsequent changes to the JComboBox in the dialog can cause more lists to be shown in various places on the screen that don't go away even when the dialog is closed. I have tried to set the first JComboBox's -state=>'disabled' before showing the dialog but that didn't help. Even though the combobox on the first window is disabled, it still pops up the list. Wow, that even confused me a little. Here is a much abbreviated example of the problem:

#!c:\perl\bin\perl.exe use strict; use warnings; use Tk; use Tk::JComboBox; use Tk::Dialog; my $form; my %choices = ( 'a'=>1, 'b'=>2, 'c'=>3 ); my $selected = "a"; CreateMainForm(); MainLoop(); exit; sub CreateMainForm { $form = MainWindow->new(); $form->title("Test for JComboBox Problem"); my $testbox1 = $form->JComboBox(-textvariable=>\$selected,-validat +e=>'match',-mode=>'editable',-relief=>'sunken',-highlightthickness=>0 +); for my $x(keys %choices) { $testbox1->addItem("$x"); } $testbox1->pack(-side=>'left'); my $button = $form->Button(-text=>"Dialog",-command=>sub{CallDialo +g($testbox1)})->pack(-side=>'right'); return; } sub CallDialog { my $otherbox = shift; $otherbox->configure(-state=>'disabled'); my $dialog = $form->Dialog(-title=>"Part2 of test",-buttons=>["Sub +mit","Cancel"],-default_button=>"Submit"); my $testbox2 = $dialog->JComboBox(-textvariable=>\$selected,-valid +ate=>'match',-mode=>'editable',-relief=>'sunken',-highlightthickness= +>0); for my $x(keys %choices) { $testbox2->addItem("$x"); } $testbox2->pack(-side=>'left'); my $retval = $dialog->Show(-popover=>$form,-overanchor=>'c',-popan +chor=>'c',-global); if($retval eq "Cancel") { $otherbox->configure(-state=>'normal'); return; } elsif($retval eq "Submit") { $otherbox->configure(-state=>'normal'); #SaveConfig(); return; } else { #should never happen return; } }

Am I doing something terribly wrong here? Is there a different/better combo box I can use?

NOTE: I have modified the JComboBox.pm slightly to handle what I like to call a loose-match in addition to the match and cs-match modes. This allows the user to enter a value not in the list as well as match items in the list while typing. This problem occurs in both the original version and my modified version.

Janitored by Arunbear - added readmore tags, as per Monastery guidelines


In reply to Help with JComboBox by ChrisR

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.