• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Editable JComboBox in swing is not allowing to type some characters

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a java file in my project that has a editable combobox, and my application is swing based application. The problem is that editable combobox is not allowing to type some characters like b,d,o, and it is also not allowing to type any numeric like 1,2,3... , but I am able to type some characters like a,c,e. So, can any one of you please help me to solve this issue. I am putting that piece of code here :

import java.awt.*;
import java.util.*;


public class MyProgram extends JPanel implements MessageListener {

public MyProgram() {
initComponents();
}

private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
comboBox1 = new JComboBox();

//======== this ========
setLayout(new GridBagLayout());
((GridBagLayout)getLayout()).columnWidths = new int[] {300, 0};
((GridBagLayout)getLayout()).rowHeights = new int[] {0, 0};
((GridBagLayout)getLayout()).columnWeights = new double[] {0.0, 1.0E-4};
((GridBagLayout)getLayout()).rowWeights = new double[] {0.0, 1.0E-4};

//---- comboBox1 ----
comboBox1.setEditable(true);
add(comboBox1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));

}

private JComboBox comboBox1;
public void receive(Message msg) {

}
}

I am waiting for your response. I hope you will cooperate me to solve this issue.

Thanks & Regards,
Debendra
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here's your code stripped of your 'personal' listener stuff

compiles/runs fine
 
Debendra nayak
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael,
I know it will work, but I am using everything as JPanel not as Frame in my project, and I am calling this program from another program in my project.So, could you please tell me how can we solve this issue with JPanel, because I dont have any main() method in my program, and everything is in JPanel.So, could you please help me to solve this issue.

Regards,
Debendra
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> could you please help me to solve this issue.

in the code you posted, there is no problem.

you need to post a sample program that produces the behavior you describe.
I don't mean a snippet here and a snippet there, or a 1000 line program.
Just enough code that produces the problem, and we can copy/paste/compile/run/observe.

should be 20-50 lines of code.
 
Debendra nayak
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael,
I am putting the complete program, and this program is called by another program(say B.java). This program is a Tab of a window(this window is belongs to B.java, I am not able to post that B.java because it is related to so many other java files in my project).

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
/*
* Created by JFormDesigner on Mon Mar 31 15:10:48 IST 2008
*/



/**
* @author User #1
*/
public class MyProgram extends JPanel{
public MyProgram() {
initComponents();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
tabbedPane1 = new JTabbedPane();
panel2 = new JPanel();
label4 = new JLabel();
label6 = new JLabel();
scrollPane3 = new JScrollPane();
list3 = new JList();
panel9 = new JPanel();
button6 = new JButton();
button7 = new JButton();
scrollPane4 = new JScrollPane();
list4 = new JList();
label5 = new JLabel();
comboBox2 = new JComboBox();
panel10 = new JPanel();
button8 = new JButton();
button5 = new JButton();

//======== tabbedPane1 ========
{

//======== panel2 ========
{
panel2.setBorder(new TitledBorder("Announcements"));
panel2.setLayout(new GridBagLayout());
((GridBagLayout)panel2.getLayout()).columnWidths = new int[] {0, 0, 0, 0};
((GridBagLayout)panel2.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0};
((GridBagLayout)panel2.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)panel2.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

//---- label4 ----
label4.setText("User groups selected");
panel2.add(label4, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));

//---- label6 ----
label6.setText("User Groups in the system");
panel2.add(label6, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 0), 0, 0));

//======== scrollPane3 ========
{
scrollPane3.setViewportView(list3);
}
panel2.add(scrollPane3, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));

//======== panel9 ========
{
panel9.setMinimumSize(new Dimension(200, 0));
panel9.setLayout(null);

//---- button6 ----
button6.setText("<<Add");
button6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button6ActionPerformed(e);
}
});
panel9.add(button6);
button6.setBounds(0, 0, 100, button6.getPreferredSize().height);

//---- button7 ----
button7.setText("Remove>>");
button7.setMinimumSize(new Dimension(200, 23));
button7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button7ActionPerformed(e);
}
});
panel9.add(button7);
button7.setBounds(0, 25, 100, button7.getPreferredSize().height);

{ // compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < panel9.getComponentCount(); i++) {
Rectangle bounds = panel9.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = panel9.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
panel9.setPreferredSize( preferredSize );
}
}
panel2.add(panel9, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));

//======== scrollPane4 ========
{
scrollPane4.setViewportView(list4);
}
panel2.add(scrollPane4, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 0), 0, 0));

//---- label5 ----
label5.setText("Announcement");
panel2.add(label5, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));

//---- comboBox2 ----
comboBox2.setEditable(true);
comboBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
comboBox1ActionPerformed(e);
}
});
panel2.add(comboBox2, new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 0), 0, 0));

//======== panel10 ========
{
panel10.setLayout(new GridLayout());

//---- button8 ----
button8.setText("Send");
button8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button8ActionPerformed(e);
}
});
panel10.add(button8);

//---- button5 ----
button5.setText("Clear");
button5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button5ActionPerformed(e);
}
});
panel10.add(button5);
}
panel2.add(panel10, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 5), 0, 0));
}
tabbedPane1.addTab("Announcement", panel2);

}
// JFormDesigner - End of component initialization //GEN-END:initComponents
}

// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private JTabbedPane tabbedPane1;
private JPanel panel2;
private JLabel label4;
private JLabel label6;
private JScrollPane scrollPane3;
private JList list3;
private JPanel panel9;
private JButton button6;
private JButton button7;
private JScrollPane scrollPane4;
private JList list4;
private JLabel label5;
private JComboBox comboBox2;
private JPanel panel10;
private JButton button8;
private JButton button5;
// JFormDesigner - End of variables declaration //GEN-END:variables

private void button6ActionPerformed(ActionEvent e) {
// TODO add your code here
}

private void button7ActionPerformed(ActionEvent e) {
// TODO add your code here
}

private void comboBox1ActionPerformed(ActionEvent e) {
// TODO add your code here
}

private void button8ActionPerformed(ActionEvent e) {
// TODO add your code here
}

private void button5ActionPerformed(ActionEvent e) {
// TODO add your code here
}
}

If you need more information I can give you. So, can you please help me to solve this issue.
[ March 31, 2008: Message edited by: Debendra Blr ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> can you please help me to solve this issue.

there is no issue with the posted code (apart from not adding the tabbedPane to the panel),
but, for me, the comboBox accepts b,d,o,1,2,3
 
reply
    Bookmark Topic Watch Topic
  • New Topic