Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Using an editable JComboBox  (Read 1027 times)
0 Members and 1 Guest are viewing this topic.
Offline King_of_Men

Senior Newbie




EUII player


« Posted 2004-06-14 01:20:09 »

I am trying to permit the player to choose from predefined factions, but allow him to rename his own if it suits him. For this, I'm trying to use an editable JComboBox. However, the box refuses to be edited. That is, it comes up on the screen as it should, and I can select my hardcoded strings; but when I click on it to try editing, it doesn't seem to gain the keyboard focus. Do I need to do anything special, other than call setEditable(true), to make it do so? Here's my code so far :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
   constructor {
      (...)
      familyChoice = Family.getFamilyChoice();
      familyChoice.setBounds(250, 50, 175, 30);
      familyChoice.setVisible(false);
      familyChoice.setEditable(true);
      getLayeredPane().add(familyChoice, JLayeredPane.PALETTE_LAYER);
   }

  // In class Family :
 public static JComboBox getFamilyChoice () {

      String[] temp = new String[allFamilies.length];
      for (int i = 0; i < temp.length; i++)
         temp[i] = allFamilies[i].name;

      return new JComboBox(temp);
   }


I call setVisible(true) in actionPerformed, and it pops up just as it should. I am not overwriting any of the painting methods. Suggestions?

To win one hundred victories, in one hundred battles, is not the acme of skill. To subdue the enemy without fighting is the acme of skill.
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #1 - Posted 2004-06-14 11:26:52 »

You are calling setEditable correctly, this seems to be spcifically a focus issue.  I noticed you are using LayeredPane stuff.. could that be affecting focus?  Can you use the TAB key to move focus to the control?  I.e. can you use any keyboard actions to select an item in that combo-box?

Offline King_of_Men

Senior Newbie




EUII player


« Reply #2 - Posted 2004-06-14 20:52:35 »

It doesn't seem to be the layeredPane, I get the same result just using the contentPane. Nix on the TAB, though I didn't see what would happen if I wrote a keyboard listener to move the focus around. I did try calling requestFocus in actionPerformed (when a button was clicked), but no dice.

However, I've decided that a TextField, with buttons on either side to traverse the names, is a cooler solution anyway. So it's not a huge priority. Would be nice to know what's going on, though. Let's hope I can give focus to a TextField.  Smiley

To win one hundred victories, in one hundred battles, is not the acme of skill. To subdue the enemy without fighting is the acme of skill.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #3 - Posted 2004-06-16 09:39:44 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
import javax.swing.*;

public class TestApp extends JFrame {
      public TestApp() {
            Container c = getContentPane();
            JComboBox jc = new JComboBox();
            c.add(jc, BorderLayout.NORTH);
            jc.setEditable(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
            show();
      }
      public static void main(String args[]) {
            TestApp t = new TestApp();
      }
}


This worked for me.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (38 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (31 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (53 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!