SetSelectedIndex() problem

I have a question on setSelectedIndex() for a combobox. First, can you use a attribute to set the index, like this:
cmbboxMapProjectionName.setSelectedIndex("infobus:/oracle/sessionInfo1/DISTINCT_MAP_PROJECTION_NAME/Id");
If you can...why am I getting the error...
D:\java_projects\MetadataBrowserTool\Main.java
Error: (1310) method setSelectedIndex(java.lang.String) not found in class oracle.dacf.control.swing.ComboBoxControl.
Thanks

The parameter for this method is an "int", not a "String". The error is correct - there is no method matching your signature.

Similar Messages

  • PROBLEM : SetSelectedIndex with MultiColumn JComboBox

    Hello,
    I've got a problem with my MultiColumn (2 Column) JComboBox.
    I had use in my ListCellRenderer a panel wich contains 2 labels (One for the code and another for the description of my item).
    Everything work very well, except the "SetSelectedIndex" and "SetSelectedItem", when i do that the label2 appears over the label1...and i obtains some very strang things....
    Is there anybody who got the solution or who got the same problem?
    Thx for the futur response.
    PS: I'm sorry for my bad english and my bad explanations, I'm french...

    Here is an example of a combo box with 2 columns using a JPanel implementing ListCellRenderer. Note that there are other ways to get appropriate background and foreground colors, but this is just a quick sample:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Test extends JFrame
         public static void main(String[] args)
              new Test();
         public Test()
              Container c = getContentPane();
              c.setLayout(new BorderLayout());
              c.setBackground(Color.gray);
              Item[] items = {
                        new Item("Item 1", "Value 1"),
                        new Item("Item 2", "Value 2"),
                        new Item("Item 3", "Value 3"),
                        new Item("Item 4", "Value 4")
              JComboBox jcb = new JComboBox(items);
              jcb.setPreferredSize(new Dimension(24, 24));
              jcb.setRenderer(new ItemRenderer());
              c.add(jcb, BorderLayout.NORTH);
              setSize(200, 100);
              setLocationRelativeTo(null);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              setVisible(true);
         // The items to display in the combobox...
         class Item
              String itemName = "";
              String itemValue = "";
              public Item(String name, String value)
                   itemName = name;
                   itemValue = value;
         // The combobox's renderer...
         class ItemRenderer extends JPanel implements ListCellRenderer
              private JLabel          nameLabel = new JLabel(" ");
              private JLabel          valueLabel = new JLabel(" ");
              public ItemRenderer()
                   setOpaque(true);
                   setLayout(new GridLayout(1, 2));
                   add(nameLabel);
                   add(valueLabel);
              public Component getListCellRendererComponent(
                                       JList list,
                                       Object value,
                                       int index,
                                       boolean isSelected,
                                       boolean cellHasFocus )
                   nameLabel.setText( ((Item)value).itemName );
                   valueLabel.setText( ((Item)value).itemValue );
                   if (isSelected)
                        setBackground(Color.black);
                        nameLabel.setForeground(Color.white);
                        valueLabel.setForeground(Color.white);
                   else
                        setBackground(Color.white);
                        nameLabel.setForeground(Color.black);
                        valueLabel.setForeground(Color.black);
                   return this;
    }I'm not sure, but the key to your problem may be with the opacity of your renderer. Let us know what you come up with. Cheers,
    Chris

  • Problems with linked ComboBoxes

    Hi everyone, and thanks to those who will reply
    It's been 3 days since i'm having the same problem :
    I have 2 comboboxes in a JPanel, and the things to be displayed in the second one depends on the first (for example selecting 'Hewlett-Packard' in the first combo box display all HP model in the second one)
    When i select a item in the first combobox, an actionPerformed is fired, and i can populate the second combobox. Unfortunately, the combobox disappear in my panel, but if i click on the place where it used to be, the popup list display correctly... !
    I just want to know hox can i make it visible anyway. I've tried combobox2.repaint() method within the actionperformed method (combobox2 is the name of my second combo box as you've guessed), but it doesnt work...
    Something else too : in my first list, if i select another vendor, the list in the second is not removed, but the list of workstation of the second-select manufacturer is appended... I've tried here the combobox2.removeall() method, but here again, no results....
    this is my code :
    public class DocPCConfig extends JFrame implements ActionListener, WindowListener
    /** D�clare les variables utilis�es **/
    JComboBox comboConstructeurs, comboMachines;
    private JPanel imagePanel, panelConstructeur, panelMachines;
    * DocPCConfig()
    * Constructeur par d�faut
    * - But : Initialise les composants Swing de la fen�tre principale
    * - E : -/-
    * - S : -/-
    public DocPCConfig()
    /** Ajoute les composants dans l'onglet **/
    ajoutCompoCstr();
    /** Ajoute un �couteur d'�v�nement de fen�tre **/
    addWindowListener(this);
    * main()
    * - But : Point d'entr�e de l'application
    * - E : String args[] : Tableau de param�tres
    * - S : -/-
    public static void main(String args[])
    System.out.println("Lancement de l'application de configuration");
    new BdD();
    mainFrame = new DocPCConfig();
    mainFrame.setSize(1024,738);
    mainFrame.setTitle("DocPCConfig");
    mainFrame.setVisible(true);
    * ajoutCompoCstr()
    * - But : Ajoute les composants pour le panel de s�lection constructeur/machine (1er onglet)
    * - E : -/-
    * - S : -/-
    public void ajoutCompoCstr()
    java.awt.GridBagConstraints gridBagConstraints1;
    /** Cr�e le vecteur stockant les r�sultats provenant de la BdD **/
    Vector listeConstructeurs = new Vector(10,5);
    /** Se connecte � la BdD **/
    BdD.connecteBdD();
    /** R�cup�re la liste des constructeurs depuis la BdD **/
    listeConstructeurs = BdD.getConstructeurs();
    DefaultComboBoxModel comboModele = new DefaultComboBoxModel(listeConstructeurs);
    BdD.deconnecteBdD();
    /** Lance le constructeur pour la liste d�roulante avec le vecteur de liste
    comme param�tre **/
    comboConstructeurs = new JComboBox(comboModele);
    /** R�gle les param�tres suppl�mentaires **/
    comboConstructeurs.setMaximumSize(new Dimension(5,5));
    comboConstructeurs.setSelectedIndex(-1);
    // comboConstructeurs.setEditable(true);
    /** Ajoute les contraintes graphiques pour la liste des constructeurs **/
    gridBagConstraints1 = new GridBagConstraints();
    gridBagConstraints1.gridx = 1;
    gridBagConstraints1.gridy = 1;
    gridBagConstraints1.insets = new Insets(10, 10, 10, 10);
    panelConstructeur.add(comboConstructeurs, gridBagConstraints1);
    comboConstructeurs.addActionListener(this);
    /** Cr�e les �l�ments de la liste d�roulante **/
    String[] listeMachines = { "                             " };
    comboMachines = new JComboBox(listeMachines);
    comboMachines.setSelectedIndex(0);
    /** Ajoute les contraintes graphiques pour la liste des machines **/
    gridBagConstraints1 = new GridBagConstraints();
    gridBagConstraints1.gridx = 1;
    gridBagConstraints1.gridy = 2;
    gridBagConstraints1.insets = new Insets(10, 10, 10, 10);
    panelConstructeur.add(comboMachines, gridBagConstraints1);
    * actionPerformed(ActionEvent ae)
    * - But : Traiter les op�ration quand une action est effectu�e sur les boutons
    * de l'interface de la fen�tre principale.
    * - E : ActionEvent ae : Un pointeur sur l'action courante.
    * - S :-/-
    public void actionPerformed(ActionEvent ae)
    Object source = ae.getSource();
    /** Liste d�roulante des constructeurs **/
    if (source == comboConstructeurs)
    /** R�cup�re la ligne s�lectionn�e dans la liste **/
    String constructeur = (String)comboConstructeurs.getSelectedItem();
    /** Creation des �l�ments de la liste d�roulante **/
    Vector listeMachines = new Vector(50,1);
    /** Se connecte � la BdD **/
    BdD.connecteBdD();
    listeMachines = BdD.getMachines(constructeur);
    /** Se d�connecte de la BdD **/
    BdD.deconnecteBdD();
    /** Supprime toutes les pr�c�dentes entr�es de la liste des machines **/
    comboMachines.removeAll();
    int i = 0;
    System.out.println(listeMachines.size());
    /** Tant que la liste n'a pas �t� parcourue **/
    while(i < listeMachines.size())
    /** Copie l'�l�ment du vecteur et l'ajoute dans la liste d�roulante **/
    comboMachines.addItem(listeMachines.elementAt(i).toString());
    i++;
    comboMachines.repaint();
    I've removed all the things I found useless, but maybe i've removed too much ;-) I hope that this code is enough.
    Thanks for your help (can you send a copy of your answers at : [email protected] - if you're too lazy to do this that's not a matter, but i don't know how i can find my post in all these posts... so that'd be cool ;-)

    Thanks Martin
    that makes sense now was driving me mad as I couldnt find anything saying it wasnt supported, makes sense seeing as its a flash server. Annoyning thing was it was playing in the content viewer locally when I previewd the folio you would think that would not be the case if it was not supported. Im going to try the rtmp links in a player in a web page and view it on the ipad out of curiosity and ill let you know. Out of interest have you done anyting with imported html into indesign as part of your folios ? I havent as yet but am curious to know how it holds up ?
    Thanks again
    Neil

  • Problem with JComboBox in aTable Cell

    I try to put JComboBox in JTableCell,
    what i want to do is something like this...
    Question | Answer |
    1. what is your favourite | a. Pizza |
    food? | b. Hot Dog |
    2. what is your favourite | a. red |
    color? | b. blue |
    Object[][] data = {
    {"1.What is your favourite food?", new AnswerChoices(new String[]{"a.Pizza","b.Hot Dog"})},
    {"2.What is your favourite color?", new AnswerChoices(new String[]{"a.red","b.blue"})}
    here my code;
    //class AnswerChoicesCellEditor
    import javax.swing.table.*;
    import javax.swing.*;
    import java.awt.Component;
    import java.awt.event.MouseEvent;
    import java.util.EventObject;
    import de.falcom.table.*;
    public class AnswerChoicesCellEditor extends AbstractCellEditor implements TableCellEditor{
         protected JComboBox mComboBox;
    public AnswerChoicesCellEditor(){
         mComboBox = new JComboBox();
         mComboBox.addActionListener(this);
         mComboBox.setEditable(false);
    public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column){
         if(value instanceof AnswerChoices){
              AnswerChoices a = (AnswerChoices)value;
              String[] c = a.getChoices();
              mComboBox.removeAllItems();
              for(int i=0; i < c.length; i++)
                   mComboBox.addItem(c);
                   mComboBox.setSelectedIndex(a.getAnswer());
         return mComboBox;
    public Object getCellEditorValue(){
         int nchoices = mComboBox.getItemCount();
         String[] c = new String[nchoices];
         for(int i = 0; i<nchoices; i++){
              c[i] = mComboBox.getItemAt(i).toString();
         return new AnswerChoices(c,mComboBox.getSelectedIndex());
         //return mComboBox.getSelectedItem(); //here i get but after selection there is no comboBox in tableCell
    //the Renderer class
    import javax.swing.table.TableCellRenderer;
    import javax.swing.*;
    import java.awt.Component;
    public class AnswerChoicesCellRenderer extends JComboBox implements TableCellRenderer {
         private Object curValue;
    /** Creates new AnswerChoiceCellRenderer */
    public AnswerChoicesCellRenderer() {
    setEditable(false);
    public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column) {
    if (value instanceof AnswerChoices) {
    AnswerChoices nl = (AnswerChoices)value;
    String[] tList = nl.getChoices();
    if (tList != null) {
    removeAllItems();
    for (int i=0; i<tList.length; i++)
    addItem(tList[i]);
         setSelectedIndex(AnswerChoices.getAnswer());
         //this.setSelectedItem();
    //return this;
    //this.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
    if (table != null)
    if (table.isCellEditable(row, column))
    setForeground(CellRendererConstants.EDITABLE_COLOR);
    else
    setForeground(CellRendererConstants.UNEDITABLE_COLOR);
              setBackground(table.getBackground());
    return this;
    public class AnswerChoices {
         static int ans = 0;
         String[] choices ;
    public AnswerChoices(String[]c,int a){
              choices = c;
              ans          = a;
    public AnswerChoices(String[] c){
              this(c,0);
    public String[] getChoices(){
         return choices;
    public void setAnswer(int a){
         ans = a;
    public static int getAnswer(){
         return ans;
    //the TableModel i used in my app
    import java.awt.Color;
    import javax.swing.JTable;
    import javax.swing.ListSelectionModel;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellEditor;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    import javax.swing.table.TableModel;
    import javax.swing.*;
    public class FAL_Table extends JTable {
    /** Creates new FAL_Table */
    public FAL_Table(DefaultTableModel dtm) {
    super(dtm);
    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    setRowSelectionAllowed(false);
    setColumnSelectionAllowed(false);
    setBackground(java.awt.Color.white);
    setDefaultCellEditorRenderer();
    private void setDefaultCellEditorRenderer(Class forClass, TableCellEditor editor, TableCellRenderer renderer) {
         setDefaultEditor(forClass, editor);
         setDefaultRenderer(forClass, renderer);
         private void setDefaultCellEditorRenderer() {
              // Setting default editor&renderer of Boolean
              setDefaultCellEditorRenderer(Boolean.class, new BooleanCellEditor(), new BooleanCellRenderer());
              //Setting default editor&renderer of ComboBox
              setDefaultCellEditorRenderer(JComboBox.class, new ComboBoxCellEditor( ),new ComboBoxRenderer());
              // Number class
              // Setting default editor&renderer of java.math.BigDecimal
              setDefaultCellEditorRenderer(java.math.BigDecimal.class,new NumberCellEditor(), new NumberCellRenderer());
              // Setting default editor&renderer of java.math.BigInteger
              setDefaultCellEditorRenderer(java.math.BigInteger.class,new NumberCellEditor(), new NumberCellRenderer());
              // Setting default editor&renderer of java.lang.Byte
              setDefaultCellEditorRenderer(Byte.class,new NumberCellEditor(), new NumberCellRenderer());
              // Setting default editor&renderer of Double
              setDefaultCellEditorRenderer(Double.class,new NumberCellEditor(), new NumberCellRenderer());
              // Setting default editor&renderer of Float
              setDefaultCellEditorRenderer(Float.class,new NumberCellEditor(), new NumberCellRenderer());
              // Setting default editor&renderer of Integer
              setDefaultCellEditorRenderer(Integer.class,new NumberCellEditor(), new NumberCellRenderer());
              // Setting default editor&renderer of Long
              setDefaultCellEditorRenderer(Long.class,new NumberCellEditor(), new NumberCellRenderer());
              // Setting default editor&renderer of Short
              setDefaultCellEditorRenderer(Short.class,new NumberCellEditor(), new NumberCellRenderer());
              // Setting default editor&renderer of String
              setDefaultCellEditorRenderer(String.class,new StringCellEditor(), new StringCellRenderer());
              // Setting default editor&renderer of FileName
              setDefaultCellEditorRenderer(FileName.class,new FileNameCellEditor(), new FileNameCellRenderer());
              // Setting default editor&renderer of Color
              setDefaultCellEditorRenderer(Color.class,new ColorCellEditor(), new ColorCellRenderer());
              setDefaultCellEditorRenderer(AnswerChoices.class, new AnswerChoicesCellEditor(), new AnswerChoicesCellRenderer());
              setDefaultCellEditorRenderer(JSpinner.class, new SpinnerCellEditor(), new SpinnerRenderer());
    public Class getCellClass(int row,int col) {
    TableModel model = getModel();
    if (model instanceof FAL_TableModel) {
    FAL_TableModel ptm = (FAL_TableModel)model;
    return ptm.getCellClass(row,convertColumnIndexToModel(col));
    return model.getColumnClass(convertColumnIndexToModel(col));
    public TableCellRenderer getCellRenderer(int row, int column) {
    TableColumn tableColumn = getColumnModel().getColumn(column);
    TableCellRenderer renderer = tableColumn.getCellRenderer();
    if (renderer == null) {
    renderer = getDefaultRenderer(getCellClass(row,column));
    return renderer;
    public TableCellEditor getCellEditor(int row, int column) {
    TableColumn tableColumn = getColumnModel().getColumn(column);
    TableCellEditor editor = tableColumn.getCellEditor();
    if (editor == null) {
    editor = getDefaultEditor(getCellClass(row,column));
    return editor;
    import javax.swing.table.*;
    import java.util.Vector;
    import java.awt.event.MouseEvent;
    import java.util.EventObject;
    public class FAL_TableModel extends DefaultTableModel implements TableModel {
    public FAL_TableModel() {
    this((Vector)null, 0);
    public FAL_TableModel(int numRows, int numColumns) {
    super(numRows,numColumns);
    public FAL_TableModel(Vector columnNames, int numRows) {
    super(columnNames,numRows);
    public FAL_TableModel(Object[] columnNames, int numRows) {
    super(convertToVector(columnNames), numRows);
    public FAL_TableModel(Vector data, Vector columnNames) {
    setDataVector(data, columnNames);
    public FAL_TableModel(Object[][] data, Object[] columnNames) {
    setDataVector(data, columnNames);
         public boolean isCellEditable(int row, int col) {
    //Note that the data/cell address is constant,
    //no matter where the cell appears onscreen.
    Object obj = getValueAt(row,col);
    if (col != 1){
    return false;
         }else{
              return true;
    public Class getCellClass(int row,int col) {
    Object obj = getValueAt(row,col);
    if (obj != null)
         return obj.getClass();
         else
         return Object.class;
    public Object getCellValue(int row,int col) {
    Object obj = getValueAt(row,col);
              return obj;      
    my problem is, when i select an item from one of the comboBox in the table the value of the other cells changes too and i have the same problem with JSpinner.
    please help i am stuck
    Gebi

    and when i try to get the current value oa a cell it returns the Component class like this
    AnswerChoices@bf1f20 ...

  • JTree Inserting Problem

    Please help me ..
    i have write a code ..which is when the user clicks the button...
    a jtree table will come and the values inside the jtree will be filled by the contents of the selected items in the form...
    but my problem is jtree only is comming
    i created the object class ... but ...
    the initialisation is not happening...
    plz check the code below .. this is my class
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    public class Reservation extends JFrame implements ItemListener,ActionListener{
         JComboBox fromCity = null;
         JComboBox toCity = null;
         JComboBox dDay = null;
         JComboBox dMonth = null;
         JComboBox dYear = null;
         JComboBox rDay = null;
         JComboBox rMonth = null;
         JComboBox rYear = null;
         JComboBox adult = null;
         JComboBox Cabin = null;
         JFrame table;
         public Reservation()
              setSize(600,400);
              JPanel p = new JPanel();
              //getContentPane().setLayout(new BorderLayout());
              GridBagLayout gbl = new GridBagLayout();
              GridBagConstraints gbc = new GridBagConstraints();
              p.setLayout(gbl);
              String []cities = {"New York","Chicago","Miami","Pittsburgh","Memphis","New Orleans"};
              String [] days={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","27","28","29","30","31"};
              String [] months = {"January","Feburary","March","April","May","June","July","August","September","October","November","December"};
              String [] year = {"2006","2007"};
              String [] adt = {"1","2","3","4"};
              String [] cab = {"Buisness","Economy"};
              fromCity = new JComboBox(cities);
              fromCity.setSelectedIndex(0);
              toCity = new JComboBox(cities);
              toCity.setSelectedIndex(0);
              dDay = new JComboBox(days);
              dMonth = new JComboBox(months);
              dYear = new JComboBox(year);
              rDay = new JComboBox(days);
              rMonth = new JComboBox(months);
              rYear = new JComboBox(year);
              adult = new JComboBox(adt);
              Cabin = new JComboBox(cab);
              JLabel frmCity = new JLabel("From");
              frmCity.setLabelFor(fromCity);
              JLabel tCity = new JLabel("To");
              tCity.setLabelFor(tCity);
              JLabel dDate = new JLabel("Departure Date");
              dDate.setLabelFor(dDate);
              JLabel rDate = new JLabel("Return Date");
              rDate.setLabelFor(rDate);
              JLabel Psg = new JLabel("Pasengers");
              Psg.setLabelFor(Psg);
              JLabel Adults = new JLabel("Adults");
              Adults.setLabelFor(Adults);
              JLabel cabin = new JLabel("Cabin");
              cabin.setLabelFor(cabin);
              JLabel search = new JLabel("Search By");
              search.setLabelFor(search);
              JRadioButton ROneWay = new JRadioButton("One Way");
              JRadioButton RRoundTrip = new JRadioButton("Round Trip");
              JButton searchbutton = new JButton("Date");
              ButtonGroup group = new ButtonGroup();
              group.add(ROneWay);
              group.add(RRoundTrip);
              gbc.gridx = 0;
              gbc.gridy = 0;
              gbc.insets = new Insets(0,30,0,0);
              p.add(frmCity,gbc);
              gbc.gridx =1;
              gbc.gridy = 0;
              gbc.insets = new Insets(0,30,0,0);
              p.add(fromCity,gbc);
              gbc.gridx =0;
              gbc.gridy = 1;
              gbc.insets = new Insets(0,30,0,0);
              p.add(tCity,gbc);
              gbc.gridx =1;
              gbc.gridy = 1;
              gbc.insets = new Insets(10,30,0,0);
              p.add(toCity,gbc);
              gbc.gridx = 0;
              gbc.gridy = 2;
              gbc.insets = new Insets(10,50,0,0);
              p.add(ROneWay,gbc);
              gbc.gridx = 1;
              gbc.gridy = 2;
              gbc.insets = new Insets(10,30,0,0);
              p.add(RRoundTrip,gbc);
              gbc.gridx = 1;
              gbc.gridy = 3;
              gbc.insets = new Insets(0,0,0,0);
              p.add(dDate,gbc);
              gbc.gridx = 0;
              gbc.gridy = 4;
              p.add(dDay,gbc);
              gbc.gridx = 1;
              gbc.gridy = 4;
              p.add(dMonth,gbc);
              gbc.gridx = 2;
              gbc.gridy = 4;
              p.add(dYear,gbc);
              gbc.gridx = 1;
              gbc.gridy = 5;
              gbc.insets = new Insets(0,0,0,0);
              p.add(rDate,gbc);
              gbc.gridx = 0;
              gbc.gridy = 6;
              p.add(rDay,gbc);
              gbc.gridx = 1;
              gbc.gridy = 6;
              p.add(rMonth,gbc);
              gbc.gridx = 2;
              gbc.gridy = 6;
              p.add(rYear,gbc);
              gbc.gridx = 1;
              gbc.gridy = 7;
              p.add(Psg,gbc);
              gbc.gridx = 0;
              gbc.gridy = 8;
              p.add(Adults,gbc);
              gbc.gridx = 1;
              gbc.gridy = 8;
              p.add(adult,gbc);
              gbc.gridx = 0;
              gbc.gridy = 9;
              p.add(cabin,gbc);
              gbc.gridx = 1;
              gbc.gridy = 9;
              gbc.insets = new Insets(10,0,0,0);
              p.add(Cabin,gbc);
              gbc.gridx = 0;
              gbc.gridy = 10;
              p.add(search,gbc);
              gbc.gridx = 1;
              gbc.gridy = 10;
              gbc.insets = new Insets(10,0,0,0);
              p.add(searchbutton,gbc);
              getContentPane().add(p);
              fromCity.addItemListener(this);
              toCity.addItemListener(this);
              dDay.addItemListener( this);
              dMonth.addItemListener( this);
              dYear.addItemListener(this);
              adult.addItemListener(this);
              Cabin.addItemListener(this);
              searchbutton.addActionListener(this);
              //Jtable form
              table = new JFrame();
              Container container;
              container = table.getContentPane();
              JPanel jpanel = new JPanel(new GridLayout(2,1));
              container.setLayout(new GridLayout(2,1));
              JLabel l1 = new JLabel("Departure Journey");
              l1.setLabelFor(l1);
              container.add(l1);
              final String[] colHeads = {"","Flightno","Date","Departure Time","Arrival Time","Flight","Duration","Fare"};
              final Object[ ][ ] data = new Object[10][10];
              JTable table = new JTable(data,colHeads);
              int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;     
              int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
              JScrollPane jsp = new JScrollPane(table,v,h);
              container.add(jsp,BorderLayout.CENTER);
         String ffcity,ttcity,dday,dmon,dyear,adt,cab;
         public void itemStateChanged(ItemEvent e)
              ffcity = (String)fromCity.getSelectedItem();
              ttcity = (String)toCity.getSelectedItem();
              dday = (String)dDay.getSelectedItem();
              dmon = (String)dMonth.getSelectedItem();
              dyear = (String)dYear.getSelectedItem();
              adt = (String)adult.getSelectedItem();
              cab = (String)Cabin.getSelectedItem();
         public void actionPerformed(ActionEvent ae)
         if(ae.getActionCommand() == "Date")
              try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection con = DriverManager.getConnection("jdbc:odbc:ds","sa", "");
              PreparedStatement stmt = con.prepareStatement("select ifno,vdtime,vatime,vdate1,vdate2,vdate3,efare from airways where fcity = ? and tcity = ? and vdate1 = ? and vdate2 = ? and vdate3 = ?");
              stmt.setString(1,ffcity);
              stmt.setString(2,ttcity);
              stmt.setString(3,dday);
              stmt.setString(4,dmon);
              stmt.setString(5,dyear);
              ResultSet d = stmt.executeQuery();
              /* int count=0;
              while(d.next())
              {count++;
              int i = 0;*/
              while(d.next())
              /*for(int j =1;j<=7;j++)
              data[i][j] = rs.getString(j);
              System.out.println(" " + data[i][j]);
              }i++;*/
              System.out.println(d.getInt(1));
              System.out.println(d.getDouble(2));
              catch(Exception ex)
                   System.out.println("Error occurred");
                   System.out.println("Error:"+ex);
              table.setVisible(true);
              table.setSize(300,200);
         private static void createAndShowGUI()
              JFrame.setDefaultLookAndFeelDecorated(true);
              Reservation r=new Reservation();
              JFrame frame = new JFrame("Reservation Form");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //r.pack();
              r.setVisible(true);
         public static void main(String[] args)
              SwingUtilities.invokeLater(new Runnable(){
                   public void run()
                        createAndShowGUI();
    in this object creation is not happening
    when i run this code ...
    only jtree is comming..
    how can i make it the values of seceted items to come in table
    i commented the parts that having error..
    when u uncomment it u will get the problem of this code

    please anyone

  • Problem with Listeners/ requestFocus()

    Hello,
    I am new to Java (started learning two months back), There is a problem with the requestFocus() in the focusListener. The program does not return the focus to the object indicated in the requestFocus but it shows multiple cusors!!
    The faculity at the institute where I am learning could not rectify the error.
    Is the error because of the myMethod() which I am using. I had made this method to prove to my professor that we can reduce the code drastically while using the gridbaglayout.
    The code which I had written is as under:
    // file name ShopperApplet.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ShopperApplet extends JApplet implements ActionListener, FocusListener,Runnable
         //static JPanel sP;
         //static JPanel oP;
         JTabbedPane tabbedPane = new JTabbedPane();
         JPanel sP;
         JPanel oP;
         JPanel pwd = new JPanel();
         // Layout Decleration of oP
         GridBagLayout ordL = new GridBagLayout();
         GridBagConstraints ordC = new GridBagConstraints();
         // Layout Decleration of sP
         FlowLayout flow = new FlowLayout();
         // Variables of sP
              JTextField textShopperId;
              JPasswordField textPassword;
              JTextField textFirstName ;
              JTextField textLastName ;
              JTextField textEmailId ;
              JTextField textAddress ;
              JComboBox comboCity ;
              JTextField textState ;
              JTextField textCountryId ;
              JTextField textZipCode ;
              JTextField textPhone ;
              JTextField textCreditCardNo ;
              JRadioButton rbVisa;
              JRadioButton rbMaster;
              JRadioButton rbAmEx;
              ButtonGroup BGccType;
              //JComboBox comboCreditCardType;
              //JTextField textExperyDate;
              JComboBox cmbDt;
              JComboBox cmbMth;
              JComboBox cmbYear;
              JButton btnSubmit;
              JButton btnReset;          
         // Variables of oP
              // Variable Decleration od oP
              JTextField txtOrderNo;
              JTextField txtToyId;
              JTextField txtQty;
              JRadioButton rbYes;     
              JRadioButton rbNo;
              ButtonGroup bgGiftWrap;
              JComboBox cmbWrapperId;
              JTextField txtMsg;
              JTextField txtToyCost;
              JButton btnOSubmit;
              JButton btnOReset;     
         // Variables of pwd
              JTextField txtShopperId;
              JPasswordField txtPassword;
              JButton btnPSubmit;
              JButton btnPReset;     
              JButton btnPNew;
              JButton btnPLogoff;
              JLabel lblN, lblN1;     
              Thread t,t1;
         Font TNR = new Font("Times New Roman",1,15);
         Font arial = new Font("Arial",2,15);
         public void sPDet()
              //Variable Decleration of sP
              textShopperId = new JTextField(6);
              textPassword = new JPasswordField(4);
              textPassword.addFocusListener(this);
              //textPassword = new JTextField(4);
              textPassword.setEchoChar('*');
              textFirstName = new JTextField(20);
              textLastName = new JTextField(20);
              textEmailId = new JTextField(25);
              textAddress = new JTextField(20);
              String cityList[] = {"New Delhi", "Mumbai", "Calcutta", "Hyderabad"};
              comboCity = new JComboBox(cityList);
              comboCity.setEditable(true);
              textState = new JTextField(30);
              textCountryId = new JTextField(25);
              textZipCode = new JTextField(6);
              textPhone = new JTextField(25);
              textCreditCardNo = new JTextField(25);
              String cardTypes[] = {"Visa", "Master Card", "American Express"};
              //comboCreditCardType = new JComboBox(cardTypes);
              rbVisa = new JRadioButton("Visa");
              rbMaster = new JRadioButton("Master Card");
              rbAmEx = new JRadioButton("American Express");
              BGccType = new ButtonGroup();
              BGccType.add(rbVisa);
              BGccType.add(rbMaster);
              BGccType.add(rbAmEx);
              String stDt[] = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
              String stMth[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
              String stYear[] = {"2001","2002","2003","2004","2005","2006","2007","2008","2009","2010"};
              cmbDt = new JComboBox(stDt);
              cmbMth = new JComboBox(stMth);
              cmbYear = new JComboBox(stYear);
              //textExperyDate = new JTextField(10);
              btnSubmit = new JButton("Submit");
              btnReset = new JButton("Reset");
              // Adding Layout Controls
              sP.setLayout(ordL);
              sP.setBackground(Color.green);
              myLayout(textShopperId,3,1,sP,"FM","Shopper Id");
              myLayout(textPassword,3,2,sP,"FM","Password");
              myLayout(textFirstName,3,3,sP,"FM","First Name") ;
              myLayout(textLastName,3,4,sP,"FM","Last Name") ;
              myLayout(textEmailId,3,5,sP,"FM","E-Mail Id") ;
              myLayout(textAddress,3,6,sP,"FM", "Address") ;
              myLayout(comboCity,3,7,sP,"FM","City") ;
              myLayout(textState,3,8,sP,"FM","State") ;
              myLayout(textCountryId,3,9,sP,"FM","Country") ;
              myLayout(textZipCode,3,10,sP,"FM","Zip Code") ;
              myLayout(textPhone,3,11,sP,"FM","Phone") ;
              myLayout(textCreditCardNo,3,12,sP,"FM","Credit Card No.") ;
              //myLayout(rbVisa,3,13,sP);
              JPanel newPanel = new JPanel();
              newPanel.add(rbVisa);
              newPanel.add(rbMaster);
              newPanel.add(rbAmEx);
              myLayout(newPanel,3,13,sP,"FM","Credit Card Type");
              //myLayout(rbMaster,4,13);
              //myLayout(rbAmEx,5,13);
              JPanel newPanel1 = new JPanel();
              newPanel1.add(cmbDt);
              newPanel1.add(cmbMth);
              newPanel1.add(cmbYear);
              myLayout(newPanel1,3,14,sP,"FM","Expiry Date");
              //myLayout(textExperyDate,3,14,sP,"FM");
              myLayout(btnSubmit,1,17,sP,"AL","Submit");
              myLayout(btnReset,3,17,sP,"AL","Reset");          
         public void oPDet()
              txtOrderNo = new JTextField(10);
              txtToyId = new JTextField(10);
              txtQty = new JTextField(10);
              rbYes = new JRadioButton("Yes");
              rbNo = new JRadioButton("No");
              bgGiftWrap = new ButtonGroup();
              bgGiftWrap.add(rbYes);
              bgGiftWrap.add(rbNo);
              String wrapperTypes[] = {"Blue Stripes", "Red Checks", "Green Crosses","Yellow Circles", "Red & Purple Stripes"};
              cmbWrapperId = new JComboBox(wrapperTypes);
              txtMsg = new JTextField(10);
              txtToyCost = new JTextField(10);
              btnOSubmit = new JButton("Submit");
              btnOReset = new JButton("Reset");
              // Adding Controls to oP
              oP.setLayout(ordL);
              oP.setBackground(Color.yellow);
              myLayout(txtOrderNo,3,1,oP,"FM","Order No.");
              myLayout(txtToyId,3,2,oP,"FM","Toy Id");
              myLayout(txtQty,3,3,oP,"FM","Quantity");
              myLayout(rbYes,3,4,oP,"M");
              myLayout(rbNo,4,4,oP,"M");
              myLayout(cmbWrapperId,3,5,oP,"M","Wrapper Id");
              myLayout(txtMsg,3,6,oP,"FM","Message");
              myLayout(txtToyCost,3,7,oP,"FM","Toy Cost");
              myLayout(btnOSubmit,1,8,oP,"AL","Submit");
              myLayout(btnOReset,3,8,oP,"AL","Reset");          
         public void pwdDet()
              pwd.setLayout(ordL);
              pwd.setBackground(Color.green);
              t = new Thread(this);
              t.start();
              t1 = new Thread(this);
              t1.start();
              lblN = new JLabel("");
              lblN1 = new JLabel("");
              txtShopperId = new JTextField(10);
              txtPassword = new JPasswordField(10);
              btnPSubmit = new JButton("Submit") ;
              btnPReset = new JButton("Reset");     
              btnPNew = new JButton("New Member");
              btnPLogoff = new JButton("Log Off");
              pwd.setLayout(ordL);
              pwd.setBackground(Color.yellow);
              myLayout(lblN,3,7,pwd);
              myLayout(lblN1,3,8,pwd);
              myLayout(txtShopperId,3,1,pwd,"FM","Shopper Id.");
              myLayout(txtPassword,3,2,pwd,"FM","Password");
              myLayout(btnPSubmit,2,4,pwd,"AL","Submit");
              myLayout(btnPReset,3,4,pwd,"AL","Reset");          
              myLayout(btnPNew,2,5,pwd,"AL","New");
              myLayout(btnPLogoff,3,5,pwd,"AL","Log Off");
         public void run()
              int ctr =0;
              String ili[] = {"India","is","a","Great","Country"};
              int ctr1 = 0;
              String iib[] = {"India","is","the","Best"};
              Thread myThread = Thread.currentThread();
              if (myThread == t)
                   while (t != null)
                        lblN.setText(ili[ctr]);
                        ctr++;
                        if (ctr >=5) ctr=0;
                        try
                             t.sleep(500);
                        catch(InterruptedException e)
                             showStatus("India is a great Country has been interrupter");
              else
                   while (t1 != null)
                        lblN1.setText(iib[ctr1]);
                        ctr1++;
                        if (ctr1 >=4) ctr1=0;
                        try
                             t1.sleep(1000);
                        catch(InterruptedException e)
                             showStatus("India is the best has been interrupter");
         public void myLayout(JComponent aObj, int x, int y, JPanel aPanel,String aListener,String toolTip)
              ordC.anchor=GridBagConstraints.NORTHWEST;
              JLabel aLabel = new JLabel(toolTip);
              ordC.gridx = x-1;
              ordC.gridy = y;
              ordL.setConstraints(aLabel,ordC);
              aPanel.add(aLabel);
              aObj.setToolTipText("Enter "+toolTip+" here");
              aObj.setForeground(Color.red);
              aObj.setBackground(Color.green);
              if (aListener.indexOf("F")     != -1)
                   aObj.addFocusListener(this);
              //if (aListener.indexOf("M")     != -1)
                   //aObj.addMouseListener(this);
              aObj.setFont(TNR);
              ordC.gridx = x;
              ordC.gridy = y;
              ordL.setConstraints(aObj,ordC);
              aPanel.add(aObj);
         public void myLayout(JComponent aObj, int x, int y, JPanel aPanel,String aListener)
              ordC.anchor=GridBagConstraints.NORTHWEST;
              aObj.setForeground(Color.red);
              aObj.setBackground(Color.green);
              if (aListener.indexOf("F")     != -1)
                   aObj.addFocusListener(this);
              //if (aListener.indexOf("M")     != -1)
                   //aObj.addMouseListener(this);
              aObj.setFont(TNR);
              ordC.gridx = x;
              ordC.gridy = y;
              ordL.setConstraints(aObj,ordC);
              aPanel.add(aObj);
         public void myLayout(JButton aObj, int x, int y, JPanel aPanel,String aListener, String toolTip)
              aObj.setToolTipText(toolTip);
              ordC.anchor=GridBagConstraints.NORTHWEST;
              aObj.setForeground(Color.red);
              if (aListener.indexOf("F")     != -1)
                   aObj.addFocusListener(this);
              //if (aListener.indexOf("M")     != -1)
                   //aObj.addMouseListener(this);
              if (aListener.indexOf("A")     != -1)
                   aObj.addActionListener(this);
              aObj.setFont(TNR);
              ordC.gridx = x;
              ordC.gridy = y;
              ordL.setConstraints(aObj,ordC);
              aPanel.add(aObj);
         public void myLayout(JTextField aObj, int x, int y, JPanel aPanel,String aListener,String toolTip)
              ordC.anchor=GridBagConstraints.NORTHWEST;
              //aObj = new JTextField(10);
              JLabel aLabel = new JLabel(toolTip);
              ordC.gridx = x-1;
              ordC.gridy = y;
              ordL.setConstraints(aLabel,ordC);
              aPanel.add(aLabel);
              aObj.setToolTipText("Enter "+toolTip+" here");
              aObj.setForeground(Color.red);
              if (aListener.indexOf("F")     != -1)
                   aObj.addFocusListener(this);
              //if (aListener.indexOf("M")     != -1)
              //     aObj.addMouseListener(this);
              if (aListener.indexOf("A")     != -1)
                   aObj.addActionListener(this);
              aObj.setFont(TNR);
              ordC.gridx = x;
              ordC.gridy = y;
              ordL.setConstraints(aObj,ordC);
              aPanel.add(aObj);
         public void myLayout(JLabel aObj, int x, int y, JPanel aPanel)
              ordC.anchor=GridBagConstraints.SOUTH;
              aObj.setForeground(Color.blue);
              aObj.setFont(TNR);
              ordC.gridx = x;
              ordC.gridy = y;
              ordL.setConstraints(aObj,ordC);
              aPanel.add(aObj);
         public void init()
              getContentPane().add(tabbedPane);
              sP = new JPanel();
              sPDet();
              oP = new JPanel();
              oPDet();
              pwdDet();
              tabbedPane.addTab("Login",null,pwd,"Login");
              tabbedPane.addTab("Shopper",null,sP,"Shopper Details");
              tabbedPane.addTab("Order",null,oP,"Order Details");
              tabbedPane.setEnabledAt(2, false);
              tabbedPane.setEnabledAt(1, false);
         public void actionPerformed(ActionEvent e)
              Object obj = e.getSource();
              if (obj == btnSubmit)
                   if (validShopperId() == false) return;
                   if (validPassword() == false) return;
                   if (validFirstName() == false) return ;
                   if (validLastName() == false) return ;
                   if (validEmailId() == false) return;
                   if (validAddress() == false) return;
                   if (validState() == false) return;
                   if (validCountryId() == false) return;
                   if (validZipCode() == false) return;
                   if (validCreditCardNo() == false) return ;
                   resetShopper();
                   tabbedPane.setEnabledAt(1,false);
                   tabbedPane.setEnabledAt(2,false);
                   tabbedPane.setSelectedIndex(0);
                   // also can be written as tabbedPane.setSelectedComponent(pwd);
                   //tabbedPane.remove(sP);
              if (obj == btnReset)
                   resetShopper();
                   tabbedPane.setEnabledAt(2,false);
                   //textExperyDate.setText("");
              if (obj == btnOSubmit)
                   if (validOrderNo() == false) return;
                   if (validToyId() == false) return;
                   if (chkNullEntry(txtQty, "Quantity")) return ;
                   if (chkNullEntry(txtToyCost, "Toy Cost")) return ;
              if (obj == btnOReset)
                   resetOrder();
              if (obj == btnPSubmit)
                   if (validPShopperId() && validPPassword())
                        tabbedPane.setEnabledAt(2, true);
                        tabbedPane.setEnabledAt(1, false);
                        txtShopperId.setText("");
                        txtPassword.setText("");
                        resetPassword();
                        //tabbedPane.addTab("Order",null,oP,"Order Details");
              if (obj == btnPReset)
                   resetPassword();
                   tabbedPane.setEnabledAt(1, false);
                   tabbedPane.setEnabledAt(2, false);
              if (obj == btnPNew)
                   tabbedPane.setEnabledAt(1, true);
                   tabbedPane.setEnabledAt(2, false);
                   resetPassword();
                   tabbedPane.setSelectedComponent(sP);
                   //tabbedPane.addTab("Shopper",null,sP,"Shopper Details");          
              if (obj == btnPLogoff)
                   tabbedPane.setEnabledAt(2, false);
                   tabbedPane.setEnabledAt(1, false);
                   resetPassword();
         public void focusGained(FocusEvent fe)
              //Object aObj = fe.getSource();
              //showStatus("Current Object is "+aObj);
         public void resetPassword()
              txtShopperId.setText("");
              txtPassword.setText("");
         public void resetShopper()
                   textShopperId.setText("");
                   textPassword.setText("");
                   textFirstName.setText("") ;
                   textLastName.setText("") ;
                   textEmailId.setText("") ;
                   textAddress.setText("") ;
                   textState.setText("") ;
                   textCountryId.setText("") ;
                   textZipCode.setText("") ;
                   textPhone.setText("") ;
                   textCreditCardNo.setText("") ;
         public void resetOrder()
              txtOrderNo.setText("");
              txtToyId.setText("");
              txtQty.setText("") ;
              txtToyCost.setText("") ;
              txtMsg.setText("") ;
         public void focusLost(FocusEvent fe)
              try{
                   Object obj = fe.getSource();
                   if (obj == textShopperId &&     validShopperId() == false)
                        //textShopperId.requestFocus();
                        return;
                   if (obj == textPassword && validPassword() == false)
                        //textPassword.requestFocus();
                        return;
                   if (obj == textFirstName && validFirstName() == false)
                        //textFirstName.requestFocus();
                        return;
                   if (obj == textEmailId && validEmailId() == false)
                        //textEmailId.requestFocus();
                        return;
                   if (obj == txtOrderNo && validOrderNo() == false)
                        //txtOrderNo.requestFocus();
                        return;
                   if (obj == txtToyId && validToyId() == false);
                        //txtToyId.requestFocus();
                        return;
              catch(Exception e)
                   showStatus("error in LostFocus() Method");
         public boolean validShopperId()
              if (chkNullEntry(textShopperId,"Shopper Id")) return false;
              return true;
         public boolean validPassword()
              if (chkNullEntry(textPassword,"Password")) return false;
              return true;
         public boolean validFirstName()
              if (chkNullEntry(textFirstName,"First Name")) return false;
              return true;
         public boolean validLastName()
              if (chkNullEntry(textLastName,"Last Name")) return false;
              return true;
         public boolean validAddress()
              if (chkNullEntry(textAddress,"Address")) return false;
              return true;
         public boolean validState()
              if (chkNullEntry(textState,"State")) return false;
              return true;
         public boolean validCountryId()
              if (chkNullEntry(textCountryId,"Country")) return false;
              return true;
         public boolean validZipCode()
              if (chkNullEntry(textZipCode,"Postal Code")) return false;
              return true;
         public boolean validCreditCardNo()
              if (chkNullEntry(textCreditCardNo,"Credit Card No.")) return false;
              return true;
         public boolean validEmailId()
              if (chkNullEntry(textEmailId,"Email Address")) return false;
              String s1 = textEmailId.getText();
              int abc = s1.indexOf("@");
              if (abc == -1 || abc == 0 || abc == (s1.length()-1))
                   JOptionPane.showMessageDialog(sP,"Invalid Email Address","Error Message",JOptionPane.ERROR_MESSAGE);
                   //textEmailId.requestFocus();
                   return false;
              return true;
         public boolean validOrderNo()
              if (chkNullEntry(txtOrderNo,"Order No.")) return false;
              return true;
         public boolean validToyId()
              if (chkNullEntry(txtToyId,"Toy Id")) return false;
              return true;
         public boolean chkNullEntry(JTextField aObj,String sDef)
              String s1 = aObj.getText();
              if (s1.length() ==0)
                   try
                        JOptionPane.showMessageDialog(sP,sDef+" cannot be left blank","Error Message",JOptionPane.ERROR_MESSAGE);
                        //showStatus(sDef+" cannot be left blank");
                        // nbvvvv vcz     z111111eeeefgggggggggg aObj.requestFocus();
                   catch(Exception e)
                        showStatus("Error in chkNullEntry() method");
                   return true ;
              else
                   return false;
         public boolean validPShopperId()
              if (chkNullEntry(txtShopperId,"Shopper Id")) return false;
              return true;
         public boolean validPPassword()
              if (chkNullEntry(txtPassword,"Password")) return false;
              return true;
    // end of code.

    Would it not be acceptable to check that each field has a value when Submit is pressed. If a field is found with no data then display the error message and return the focus to the empty field. This would solve the multiple cursors problem as you would not need any focusLost handler code.
    If this is entirely out of the question then you will have to override some of the FocusManager methods to prevent the JVM from handling focus for you :
    FocusManager.setCurrentManager(new DefaultFocusManager() {
      // Override FocusManager methods here.
    });Ronny.

  • Problem with focus border and ListCellRenderer in custom listbox

    I have a bug in some code that I adapted from another posting on this board -- basically what I've done is I have a class that implements a custom "key/value" mapping listbox in which each list item/cell is actually a JPanel consisting of 3 JLabels: the first label is the "key", the second is a fixed "==>" mapping string, and the 3rd is the value to which "key" is mapped.
    The code works fine as long as the list cell doesn't have the focus. When it does, it draws a border rectangle to indicate focus, but if the listbox needs to scroll horizontally to display all the text, part of the text gets cut off (i.e. "sometex..." where "sometext" should be displayed).
    The ListCellRenderer creates a Gridlayout to lay out the 3 labels in the cell's JPanel.
    What can I do to remedy this situation? I'm not sure what I'd need to do in terms of setting the size of the panel so that all the text gets displayed OK within the listbox. Or if there's something else I can do to fix this. The code and a main() to run the code are provided below. To reproduce the problem, click the Add Left and Add Right buttons to add a "mapping" -- when it doesn't have focus, everything displays fine, but when you give it focus, note the text on the right label gets cut off.
    //======================================================================
    // Begin Source Listing
    //======================================================================
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.Vector;
    import java.util.Enumeration;
    public class TwoColumnListbox extends JPanel
    private JList m_list;
    private JScrollPane m_Pane;
    public TwoColumnListbox(Collection c)
         DataMapListModel model = new DataMapListModel();
         if (c != null)
         Iterator it = c.iterator();
         while (it.hasNext())
         model.addElement(it.next());
         m_list = new JList(model);
         ListBoxRenderer renderer= new ListBoxRenderer();
              m_list.setCellRenderer(renderer);
              setLayout(new BorderLayout());
              m_list.setVisibleRowCount(4);
              m_Pane = new JScrollPane(m_list);
              add(m_Pane, BorderLayout.NORTH);
    public JList getList()
    return m_list;
    public JScrollPane getScrollPane()
    return m_Pane;
    public static void main(String s[])
              JFrame frame = new JFrame("TwoColumnListbox");
              frame.addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent e) {System.exit(0);}
    final DataMappings dm = new DataMappings();
    final TwoColumnListbox lb = new TwoColumnListbox(dm.getMappings());
              final DataMap map = new DataMap();
              JButton leftAddBtn = new JButton("Add Left");
              leftAddBtn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e)
              map.setSource("JButton1");
              DefaultListModel model = new DefaultListModel();
              model.addElement(map);
              lb.getList().setModel(model);
              JButton leftRemoveBtn = new JButton("Remove Left");
              leftRemoveBtn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e)
              map.setSource("");
              DefaultListModel model = new DefaultListModel();
              model.addElement(map);
              lb.getList().setModel(model);
              JButton rightAddBtn = new JButton("Add Right");
    rightAddBtn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e)
              map.setDestination("/getQuote/symbol[]");
              DefaultListModel model = new DefaultListModel();
              model.addElement(map);
              lb.getList().setModel(model);
              JButton rightRemoveBtn = new JButton("Remove Right");
    rightRemoveBtn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e)
              map.setDestination("");
              DefaultListModel model = new DefaultListModel();
              model.addElement(map);
              lb.getList().setModel(model);
              JPanel leftPanel = new JPanel(new BorderLayout());
              leftPanel.add(leftAddBtn, BorderLayout.NORTH);
              leftPanel.add(leftRemoveBtn, BorderLayout.SOUTH);
    JPanel rightPanel = new JPanel(new BorderLayout());
              rightPanel.add(rightAddBtn, BorderLayout.NORTH);
              rightPanel.add(rightRemoveBtn, BorderLayout.SOUTH);
    frame.getContentPane().add(leftPanel, BorderLayout.WEST);
              frame.getContentPane().add(lb,BorderLayout.CENTER);
    frame.getContentPane().add(rightPanel, BorderLayout.EAST);
              frame.pack();
              frame.setVisible(true);
         class ListBoxRenderer extends JPanel implements ListCellRenderer
              private JLabel left;
              private JLabel arrow;
              private JLabel right;
              private Color clrForeground = UIManager.getColor("List.foreground");
    private Color clrBackground = UIManager.getColor("List.background");
    private Color clrSelectionForeground = UIManager.getColor("List.selectionForeground");
    private Color clrSelectionBackground = UIManager.getColor("List.selection.Background");
              public ListBoxRenderer()
                   setLayout(new GridLayout(1, 2, 10, 0));
                   //setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
                   left = new JLabel("");
                   left.setForeground(clrForeground);               
                   arrow = new JLabel("");
                   arrow.setHorizontalAlignment(SwingConstants.CENTER);
                   arrow.setForeground(clrForeground);
                   right = new JLabel("");
                   right.setHorizontalAlignment(SwingConstants.RIGHT);
                   right.setForeground(clrForeground);
                   add(left);
                   add(arrow);
                   add(right);
              public Component getListCellRendererComponent(JList list, Object value,
                        int index, boolean isSelected, boolean cellHasFocus)
                   if (isSelected)
                        setBackground(list.getSelectionBackground());
                        setForeground(list.getSelectionForeground());
                        left.setForeground(clrSelectionForeground);
                        arrow.setForeground(clrSelectionForeground);
                        right.setForeground(clrSelectionForeground);
                   else
                        setBackground(list.getBackground());
                        setForeground(list.getForeground());
                   left.setForeground(clrForeground);
                        arrow.setForeground(clrForeground);
                        right.setForeground(clrForeground);               
                   // draw focus rectangle if control has focus. Problem with focus
    // and cut off text!!
                   if (cellHasFocus)
                   // FIXME: for Windows LAF I'm not getting the correct thing here for some reason.
                   // Looks OK on Metal though.
                   setBorder(BorderFactory.createLineBorder(UIManager.getColor("focusCellHighlightBorder")));
                   else
                   setBorder(BorderFactory.createEmptyBorder());               
    DataMap map = (DataMap) value;
                   String displaySource = map.getSource();
                   String displayDest = map.getDestination();
                   left.setText(displaySource);
                   arrow.setText("=>to<=");
                   right.setText(displayDest);
                   return this;
    /** Interface for macro editor UI
    * @version 1.0
    class DataMappings
    private Collection mappings;
    public DataMappings()
    setMappings(new Vector(0));
    public DataMappings(Collection maps)
    setMappings(maps);
    /** gets mapping value of a specified source object
    * @param src -- the "key" or source object, what is mapped.
    * @return what the source object is mapped to
    * @version 1.0
    public Object getValue(String src)
    if (src != null)
    Iterator it = mappings.iterator();
    while (it.hasNext());
    DataMap thisMap = (DataMap) it.next();
    if (thisMap.getSource().equals(src))
    return thisMap.getDestination();
    return null;
    /** sets mapping value of a specified source object
    * @param src -- the "key" or source object, what is mapped.
    * @param what the source object is to be mapped to
    * @version 1.0
    public void setValue(String src, String dest)
    if (src != null)
    // see if the value is in there first.
    Iterator it = mappings.iterator();
    while (it.hasNext())
    DataMap thisMap = (DataMap) it.next();
    if (thisMap.getSource().equals(src))
    thisMap.setDestination(dest);
    return;
    // not in the collection, add it
    mappings.add(new DataMap(src, dest));
    /** gets collection of mappings
    * @return a collection of all mappings in this object.
    * @version 1.0
    public Collection getMappings()
    return mappings;
    /** sets collection of mappings
    * @param maps a collection of src to destination mappings.
    * @version 1.0
    public void setMappings(Collection maps)
    mappings = maps;
    /** adds a DataMap
    * @param map a DataMap to add to the mappings
    * @version 1.0
    public void add(DataMap map)
    if (map != null)
    mappings.add(map);
    class DataMap
    public DataMap() {}
    public DataMap(String source, String destination)
    m_source = source;
    m_destination = destination;
    public String getSource()
    return m_source;
    public void setSource(String s)
    m_source = s;
    public String getDestination()
    return m_destination;
    public void setDestination(String s)
    m_destination = s;
    protected String m_source = null;
    protected String m_destination = null;
    /** list model for datamaps that provides ways
    * to determine whether a source is already mapped or
    * a destination is already mapped.
    class DataMapListModel extends DefaultListModel
    public DataMapListModel()
    super();          
    /** determines whether a source is already mapped
    * @param src -- the source property of a datamapping
    * @return true if the source is in the list, false if not
    public boolean containsSource(Object src)
    Enumeration enum = elements();
    while (enum.hasMoreElements())
    DataMap dm = (DataMap) enum.nextElement();
    if (dm.getSource().equals(src))
    return true;
    return false;
    /** determines whether a destination is already mapped
    * @param dest -- the destination property of a datamapping
    * @return true if the destination is in the list, false if not
    public boolean containsDest(Object dest)
    Enumeration enum = elements();
    while (enum.hasMoreElements())
    DataMap dm = (DataMap) enum.nextElement();
    if (dm.getDestination().equals(dest))
    return true;
    return false;
    public DataMappings getDataMaps()
    DataMappings maps = new DataMappings();
    // add all the datamaps in the model
    Enumeration enum = elements();
    while (enum.hasMoreElements())
    DataMap dm = (DataMap) enum.nextElement();
    maps.add(dm);
    return maps;
    //======================================================================
    // End of Source Listing
    //======================================================================

    I did not read the program, but the chopping looks like a layout problem.
    I think it's heavy to use a panel + 3 components in a gridlayout for each cell. look at this sample where i draw the Cell myself,
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.*;
    public class Jlist3 extends JFrame 
         Vector      v  = new Vector();
         JList       jc = new JList(v);
         JScrollPane js = new JScrollPane(jc);
    public Jlist3()
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);}});
         for (int j=0; j < 70; j++)     v.add(""+j*1000+"a  d"+j);
           setBounds(1,1,400,310);
         getContentPane().add(js);
         js.setPreferredSize(new Dimension(230,259));
         jc.setSelectedIndex(1);
         jc.setCellRenderer(new MyCellRenderer());
         getContentPane().setLayout(new FlowLayout());
         setVisible(true);
    public class MyCellRenderer extends JLabel implements ListCellRenderer
         String  txt;
         int     idx;
         boolean sel;
    public Component getListCellRendererComponent(JList list,
                             Object  value,           // value to display
                             int     index,           // cell index
                             boolean isSelected,      // is the cell selected
                             boolean cellHasFocus)    // the list and the cell have the focus
         idx = index;
         txt = value.toString();
         sel = isSelected;
         setText(txt);
         return(this);
    public void paintComponent(Graphics g)
         if (idx%2 == 1) g.setColor(Color.white);
              else        g.setColor(Color.lightGray);
         if (sel)        g.setColor(Color.blue);
         g.fillRect(0,0,getWidth(),getHeight());
         StringTokenizer st = new StringTokenizer(txt.trim()," ");
         g.setColor(Color.black);
         if (st.hasMoreTokens())     g.drawString(st.nextToken(),1,14);
         g.setColor(Color.red);
         g.drawString("===>",70,14);
         g.setColor(Color.black);
         if (st.hasMoreTokens())     g.drawString(st.nextToken(),110,14);
    public static void main (String[] args) 
         new Jlist3();
    Noah
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.*;
    public class Jlist3 extends JFrame
         Vector v = new Vector();
         JList jc = new JList(v);
         JScrollPane js = new JScrollPane(jc);
    public Jlist3()
         addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);}});
         for (int j=0; j < 70; j++)     v.add(""+j*1000+"a d"+j);
         setBounds(1,1,400,310);
         getContentPane().add(js);
         js.setPreferredSize(new Dimension(230,259));
         jc.setSelectedIndex(1);
         jc.setCellRenderer(new MyCellRenderer());
         getContentPane().setLayout(new FlowLayout());
         setVisible(true);
    public class MyCellRenderer extends JLabel implements ListCellRenderer
         String txt;
         int idx;
         boolean sel;
    public Component getListCellRendererComponent(JList list,
                             Object value, // value to display
                             int index, // cell index
                             boolean isSelected, // is the cell selected
                             boolean cellHasFocus) // the list and the cell have the focus
         idx = index;
         txt = value.toString();
         sel = isSelected;
         setText(txt);
         return(this);
    public void paintComponent(Graphics g)
         if (idx%2 == 1) g.setColor(Color.white);
              else g.setColor(Color.lightGray);
         if (sel) g.setColor(Color.blue);
         g.fillRect(0,0,getWidth(),getHeight());
         StringTokenizer st = new StringTokenizer(txt.trim()," ");
         g.setColor(Color.black);
         if (st.hasMoreTokens())     g.drawString(st.nextToken(),1,14);
         g.setColor(Color.red);
         g.drawString("===>",70,14);
         g.setColor(Color.black);
         if (st.hasMoreTokens())     g.drawString(st.nextToken(),110,14);
    public static void main (String[] args)
         new Jlist3();
    }

  • Problem in refreshing the combo box on selection of an item in another comb

    I have a situation where values to be displayed in 2nd combo box depends on the selection of an item from the 1st combo box.
    Problem observed:
    The 2nd combo box is not getting refreshed if the selected item from the 1st combo box has mapping to more than 10 items.
    for ex:
    A - AA, AB, AC, AD, AE, AF
    B - BA, BB, BC, BD, BE, BF, BG, BH, BI, BJ, BK, BL, BM, BN, BO, BP
    C - CA, CB, CC
    D - DA, DB, DC, DD
    1st combo box list:
    A
    B
    C
    D
    2nd combo box list:
    If the value selected from the first combo box is A, C, or D then 2nd combo box refreshes with repective values. But when the value selected is B, then 2nd combo box is not getting refreshed with respective values.
    Combo Model for 1st combo box:
    public class proCLMLossTypeComboModel implements javax.swing.ComboBoxModel
    package nz.co.towerinsurance.quantum.claims.pro;
    import javax.swing.*;
    import java.util.*;
    import CoreProduct.mbsoPRDLossCauseTypeList;
    import javax.swing.event.*;
    public class proCLMLossTypeComboModel implements javax.swing.ComboBoxModel
    Vector vector = null;
    mbsoPRDLossCauseTypeList mbsoPRDLossCauseTypeListInst0 = null;
    public void setData(Vector vector)
    this.vector = vector;
    public int getSize()
    if(vector != null)
    return this.vector.size();     
    else
    return 0;
    public void addListDataListener(ListDataListener l)
    public void removeListDataListener(ListDataListener l)
    public Object getElementAt(int index)
    return this.vector.elementAt(index);     
    public Object getSelectedItem()
    return this.mbsoPRDLossCauseTypeListInst0;     
    public void setSelectedItem(Object anItem)
    mbsoPRDLossCauseTypeList mbsoPRDLossCauseTypeListInst1 = (mbsoPRDLossCauseTypeList)anItem;
    this.mbsoPRDLossCauseTypeListInst0 = mbsoPRDLossCauseTypeListInst1;
    public Vector getData()
    return this.vector;     
    Combo Model for 2nd combo box:
    package nz.co.towerinsurance.quantum.claims.pro;
    import javax.swing.*;
    import java.util.*;
    import CoreProduct.mbsoPRDCauseTypeList;
    import javax.swing.event.*;
    public class proCLMCauseTypeComboModel implements javax.swing.ComboBoxModel
    Vector vector = null;
    mbsoPRDCauseTypeList mbsoPRDCauseTypeListInst0 = null;
    public void setData(Vector vector)
    this.vector = vector;
    public int getSize()
    if(vector != null)
    return this.vector.size();     
    else
    return 0;
    public void addListDataListener(ListDataListener l)
    public void removeListDataListener(ListDataListener l)
    public Object getElementAt(int index)
    return this.vector.elementAt(index);     
    public Object getSelectedItem()
    return this.mbsoPRDCauseTypeListInst0;     
    public void setSelectedItem(Object anItem)
    mbsoPRDCauseTypeList mbsoPRDCauseTypeListInst1 = (mbsoPRDCauseTypeList)anItem;
    this.mbsoPRDCauseTypeListInst0 = mbsoPRDCauseTypeListInst1;
    public Vector getData()
    return this.vector;     
    The Panel inside which these combo boxes are used:
    package nz.co.towerinsurance.quantum.claims.pro;
    import nz.co.towerinsurance.quantum.logger.MessageLogger;
    import nz.co.towerinsurance.quantum.claims.vmo.*;
    import nz.co.towerinsurance.quantum.utility.uhoUTLDialogueContext;
    import nz.co.towerinsurance.quantum.utility.uhoUTLModelHolder;
    import nz.co.towerinsurance.quantum.utility.uhoUTLInteraction;
    import nz.co.towerinsurance.quantum.utility.uhoUTLNotesContext;
    import nz.co.towerinsurance.quantum.utility.uhoUTLPrivacyContext;
    import nz.co.towerinsurance.quantum.utility.uhoUTLProcessImpContext;
    import nz.co.towerinsurance.quantum.help.*;
    import nz.co.towerinsurance.quantum.document.*;
    import nz.co.towerinsurance.quantum.task.*;
    import nz.co.towerinsurance.quantum.qtm.*;
    import nz.co.towerinsurance.quantum.claims.uhoCLMClientModel;
    import nz.co.towerinsurance.quantum.claims.utility.*;
    import MCType.*;
    import Claim.*;
    import Client.*;
    import Policy.*;
    import CoreProduct.*;
    import Security.*;
    import MCUtil.*;
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import javax.swing.ButtonGroup.*;
    import java.text.*;
    public class proSummaryPanel extends proCLMPanelBase implements proCLMRefreshInterface, proCLMDeclineReasonInterface
    private static final MessageLogger msgLogger=MessageLogger.getLogger("claims.pro.proSummaryPanel");
    uhoCLMClientModel uhoCLMClientModelInst0 = null;
    Vector VectorInst0 = new Vector();
    JRadioButton jRdBtnSummaryPM = new JRadioButton();
    JRadioButton jRdBtnSummaryAM = new JRadioButton();
    ButtonGroup ButtonGroupInst0 = new ButtonGroup();
    JButton jBtnSummarySearch = new JButton();
    JLabel jLblSummaryCompanyName = new JLabel();
    JLabel jLblSummaryCauseType = new JLabel();
    JTextField jTxtFldSummaryAmountSaved = new JTextField();
    JTextField jTxtFldSummaryDateNotified = new JTextField();
    JTextField jTxtFldSummary = new JTextField();
    JTextField jTxtFldSummarySuburb = new JTextField();
    JLabel jLblSummaryCatCode = new JLabel();
    JLabel jLblSummaryLossDesc = new JLabel();
    JLabel jLblSummaryDateNotified = new JLabel();
    JLabel jLblSummaryCity = new JLabel();
    JLabel jLblSummaryTime = new JLabel();
    JLabel jLblSummaryDeclineReason = new JLabel();
    JCheckBox jChkBxNcbLost = new JCheckBox();
    JCheckBox jChkBxLegal = new JCheckBox();
    JCheckBox jChkBxNoBlameBonus = new JCheckBox();
    JLabel jLblSummaryPostCode = new JLabel();
    JTextField jTxtFldSummaryStreetName = new JTextField();
    JTextField jTxtFldSummaryLossDate = new JTextField();
    JTextField jTxtFldSummaryCity = new JTextField();
    JTextField jTxtFldSummaryTime = new JTextField();
    JLabel jLblSummaryLossType = new JLabel();
    JTextField jTxtFldSummaryPhone = new JTextField();
    JTextField jTxtFldSummaryCompanyName = new JTextField();
    JLabel jLblSummarySuburb = new JLabel();
    JTextArea jTxtArLossDescription = new JTextArea();
    JScrollPane jScrPnSummaryLossDesc = new JScrollPane(jTxtArLossDescription);
    JTextField jTxtFldSummaryDeclineReason = new JTextField();
    JPanel jPanel2 = new JPanel();
    JPanel jPanel1 = this;
    JLabel jLblSummaryPhone = new JLabel();
    JTextField jTxtFldSummaryPostCode = new JTextField();
    JLabel jLblSummaryAmountSaved = new JLabel();
    JPanel jPnlSummaryCoy = new JPanel();
    JLabel jLblSummaryStreetName = new JLabel();
    Vector lossTypeVec = new Vector();
    JComboBox jCmbBxSummaryLossType = new JComboBox(lossTypeVec);
    proCLMLossTypeComboModel lossTypeComboModel = new proCLMLossTypeComboModel();
    Vector causeTypeVec = new Vector();
    JComboBox jCmbBxSummaryCauseType = new JComboBox();
    proCLMCauseTypeComboModel causeTypeComboModel = new proCLMCauseTypeComboModel();
    Vector CatCodeVec = new Vector();
    JComboBox jCmbBxSummaryCatCode = new JComboBox();
    proCLMCatCodeComboModel catCodeComboModel = new proCLMCatCodeComboModel();
    JLabel jLblSummaryLossDate = new JLabel();
    JButton jBtnSave = new JButton();
    JButton jBtnCancel = new JButton();
    Border border1;
    TitledBorder titledBorder1;
    Border border2;
    Border border3;
    TitledBorder titledBorder2;
    Border border4;
    TitledBorder titledBorder3;
    GridBagLayout gridBagLayout1 = new GridBagLayout();
    GridBagLayout gridBagLayout2 = new GridBagLayout();
    Border border5;
    TitledBorder titledBorder4;
    GridBagLayout gridBagLayout3 = new GridBagLayout();
    GridBagLayout gridBagLayout4 = new GridBagLayout();
    Component component1;
    Component component2;
    * @parameter uhoUTLInteraction ,mbsoSEMPrivilege
    * @return
    public proSummaryPanel(proQTMBase parent, uhoUTLInteraction inter,mbsoSEMPrivilege services)
    super(parent,inter,services);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    * Component initialization
    * @parameter
    * @return void
    private void jbInit() throws Exception
    component1 = Box.createHorizontalStrut(8);
    component2 = Box.createHorizontalStrut(8);
    jCmbBxSummaryLossType.setMinimumSize(new Dimension(225, 25));
    // set the combo models
    jCmbBxSummaryLossType.setModel(lossTypeComboModel);
    jCmbBxSummaryCauseType.setModel(causeTypeComboModel);
    jCmbBxSummaryCatCode.setModel(catCodeComboModel);
    // renderer for the loss type combo
         jCmbBxSummaryLossType.setRenderer(new DefaultListCellRenderer()
         public Component getListCellRendererComponent(JList list, Object value,
         int index, boolean isSelected, boolean cellHasFocus)
         mbsoPRDLossCauseTypeList mbsoPRDLossTypeListObj = (mbsoPRDLossCauseTypeList) value;
         String v = (mbsoPRDLossTypeListObj == null) ? null:mbsoPRDLossTypeListObj.GetLossTypeName().toString();
         return super.getListCellRendererComponent(list,v,index,isSelected,cellHasFocus);
         // key selection manager for loss type combo
         jCmbBxSummaryLossType.setKeySelectionManager(new javax.swing.JComboBox.KeySelectionManager()
         public int selectionForKey(char aKey,ComboBoxModel aModel)
         try
         Vector vector = lossTypeComboModel.getData();
         // prepare a character array witht the first letter of loss types in lower case
         char[] characterArray = new char[vector.size()];
         for(int i=0;i<vector.size();i++)
         mbsoPRDLossCauseTypeList mbsoPRDLossCauseTypeListInst0 = (mbsoPRDLossCauseTypeList)vector.elementAt(i);
         char charac = mbsoPRDLossCauseTypeListInst0.GetLossTypeName().toString().toLowerCase().charAt(0);     
         characterArray[i] = charac;
         Character char1 = new Character(aKey);
         int index = 0;
         if(char1.isUpperCase(aKey))
         char char2 = char1.toLowerCase(aKey);
         index = java.util.Arrays.binarySearch(characterArray,char2);
         else
         index = java.util.Arrays.binarySearch(characterArray,aKey);
         if(index > 0)
         jCmbBxSummaryLossType.setSelectedIndex(index);
         else
         jCmbBxSummaryLossType.setSelectedIndex(0);
         jCmbBxSummaryLossType.repaint();
         if(index > 0)
         return index;
         else
         return 0;
         catch(Exception e1)
         msgLogger.fatal("Exception     : proSumamryPanel     : loss type combo key sel mgr : "+e1.getMessage());
         return 0;
         // renderer for cause type combo
         jCmbBxSummaryCauseType.setRenderer(new DefaultListCellRenderer() {
         public Component getListCellRendererComponent(JList list, Object value,
         int index, boolean isSelected, boolean cellHasFocus)
         mbsoPRDCauseTypeList mbsoPRDCauseTypeListObj = (mbsoPRDCauseTypeList) value;
         String v = (mbsoPRDCauseTypeListObj == null) ? null:mbsoPRDCauseTypeListObj.GetCauseTypeName().toString();
         return super.getListCellRendererComponent(list,v,index,isSelected,cellHasFocus);
         // key selection manager for loss type combo
         jCmbBxSummaryCauseType.setKeySelectionManager(new javax.swing.JComboBox.KeySelectionManager()
         public int selectionForKey(char aKey,ComboBoxModel aModel)
         try
         Vector vector = causeTypeComboModel.getData();
         // prepare a character array witht the first letter of loss types in lower case
         char[] characterArray = new char[vector.size()];
         for(int i=0;i<vector.size();i++)
         mbsoPRDCauseTypeList mbsoPRDCauseTypeListInst0 = (mbsoPRDCauseTypeList)vector.elementAt(i);
         char charac = mbsoPRDCauseTypeListInst0.GetCauseTypeName().toString().toLowerCase().charAt(0);     
         characterArray[i] = charac;
         Character char1 = new Character(aKey);
         int index = 0;
         if(char1.isUpperCase(aKey))
         char char2 = char1.toLowerCase(aKey);
         index = java.util.Arrays.binarySearch(characterArray,char2);
         else
         index = java.util.Arrays.binarySearch(characterArray,aKey);
         if(index > 0)
         jCmbBxSummaryCauseType.setSelectedIndex(index);
         else
         jCmbBxSummaryCauseType.setSelectedIndex(0);
         jCmbBxSummaryCauseType.repaint();
         if(index > 0)
         return index;
         else
         return 0;
         catch(Exception e1)
         msgLogger.fatal("Exception     : proSumamryPanel     : cause type combo key sel mgr : "+e1.getMessage());
         return 0;
    jBtnSummarySearch.setBorder(BorderFactory.createRaisedBevelBorder());
    jBtnSummarySearch.setMaximumSize(new Dimension(119, 23));
    jBtnSummarySearch.setPreferredSize(new Dimension(65, 23));
    jBtnSummarySearch.setMnemonic(KeyEvent.VK_E); // 20/12
    jBtnSummarySearch.setText("Search");
    this.setLayout(gridBagLayout4);
    ButtonGroupInst0.add(jRdBtnSummaryPM);
    ButtonGroupInst0.add(jRdBtnSummaryAM);
    border1 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142));
    titledBorder1 = new TitledBorder(border1,"Where Is It Now?");
    border2 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142));
    border3 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142));
    titledBorder2 = new TitledBorder(border3,"Where Is It Now?");
    border4 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142));
    titledBorder3 = new TitledBorder(border4,"Summary");
    border5 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142));
    titledBorder4 = new TitledBorder(border5,"Location of Vehicle/Boat");
    jScrPnSummaryLossDesc.setToolTipText("");
    jScrPnSummaryLossDesc.setFont(new java.awt.Font("SansSerif", 0, 12));
    jScrPnSummaryLossDesc.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jLblSummarySuburb.setText("Suburb");
    jLblSummarySuburb.setForeground(Color.black);
    jLblSummarySuburb.setPreferredSize(new Dimension(100, 17));
    jLblSummarySuburb.setFont(new java.awt.Font("SansSerif", 1, 12));
    jTxtFldSummaryCompanyName.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryCompanyName.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryCompanyName.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryCompanyName.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryPhone.setToolTipText("");
    jTxtFldSummaryPhone.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryPhone.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryPhone.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryPhone.setFont(new java.awt.Font("SansSerif", 0, 12));
    jLblSummaryLossType.setText("Loss Type");
    jLblSummaryLossType.setForeground(Color.black);
    jLblSummaryLossType.setPreferredSize(new Dimension(102, 17));
    jLblSummaryLossType.setFont(new java.awt.Font("SansSerif", 1, 12));
    jTxtFldSummaryTime.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryTime.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryTime.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryTime.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryCity.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryCity.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryCity.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryCity.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryLossDate.setBackground(Color.cyan);
    jTxtFldSummaryLossDate.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryLossDate.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryLossDate.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryLossDate.setFont(new java.awt.Font("SansSerif", 0, 12));
    jBtnSave.setToolTipText("");
    jBtnSave.setBorder(BorderFactory.createRaisedBevelBorder());
    jBtnSave.setMnemonic('S');
    jBtnSave.setText("Save");
    jBtnSave.setPreferredSize(new Dimension(100,23)); // 30/07
    jBtnSummarySearch.addActionListener(new java.awt.event.ActionListener(){
    public void actionPerformed(ActionEvent e) {
    jBtnSummarySearch_actionPerformed(e);
    //the listener for losstype combobox
    jCmbBxSummaryLossType.addItemListener(new java.awt.event.ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    jCmbBxSummaryLossType_itemStateChanged(e);
    //Actioin listener for Save button
    jBtnSave.addActionListener(new java.awt.event.ActionListener()
    public void actionPerformed(ActionEvent e)
    jBtnSave_actionPerformed(e);
    //Actioin listener for Cancel button
    jTxtFldSummaryStreetName.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryStreetName.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryStreetName.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryStreetName.setPreferredSize(new Dimension(100, 20));
    jLblSummaryPostCode.setText("Post Code");
    jLblSummaryPostCode.setForeground(Color.black);
    jLblSummaryPostCode.setPreferredSize(new Dimension(100, 17));
    jLblSummaryPostCode.setFont(new java.awt.Font("SansSerif", 1, 12));
    jChkBxNcbLost.setFont(new java.awt.Font("SansSerif", 1, 12));
    jChkBxNcbLost.setPreferredSize(new Dimension(130, 17));
    jChkBxNcbLost.setText("NCB Lost");
    jLblSummaryDeclineReason.setText("Decline Reason");
    jLblSummaryDeclineReason.setForeground(Color.black);
    jLblSummaryDeclineReason.setPreferredSize(new Dimension(102, 17));
    jLblSummaryDeclineReason.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryTime.setText("Time");
    jLblSummaryTime.setForeground(Color.black);
    jLblSummaryTime.setPreferredSize(new Dimension(35, 17));
    jLblSummaryTime.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryCity.setText("Town/City");
    jLblSummaryCity.setForeground(Color.black);
    jLblSummaryCity.setPreferredSize(new Dimension(100, 17));
    jLblSummaryCity.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryDateNotified.setText("Date Notified");
    jLblSummaryDateNotified.setForeground(Color.black);
    jLblSummaryDateNotified.setPreferredSize(new Dimension(102, 17));
    jLblSummaryDateNotified.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryLossDesc.setText("Loss Description");
    jLblSummaryLossDesc.setForeground(Color.black);
    jLblSummaryLossDesc.setPreferredSize(new Dimension(102, 17));
    jLblSummaryLossDesc.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryCatCode.setText("Catastrophe Code");
    jLblSummaryCatCode.setForeground(Color.black);
    jLblSummaryCatCode.setFont(new java.awt.Font("SansSerif", 1, 12));
    jTxtFldSummarySuburb.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummarySuburb.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummarySuburb.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummarySuburb.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryAmountSaved.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryAmountSaved.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryAmountSaved.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryAmountSaved.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryDateNotified.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryDateNotified.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryDateNotified.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryDateNotified.setPreferredSize(new Dimension(100, 20));
    jLblSummaryCauseType.setText("Cause Type");
    jLblSummaryCauseType.setForeground(Color.black);
    jLblSummaryCauseType.setPreferredSize(new Dimension(102, 17));
    jLblSummaryCauseType.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryCompanyName.setText("Company Name");
    jLblSummaryCompanyName.setForeground(Color.black);
    jLblSummaryCompanyName.setPreferredSize(new Dimension(100, 17));
    jLblSummaryCompanyName.setFont(new java.awt.Font("SansSerif", 1, 12));
    jCmbBxSummaryCatCode.setFont(new java.awt.Font("SansSerif", 0, 12));
    jCmbBxSummaryCatCode.setMinimumSize(new Dimension(225, 25));  // on 21/11
    jCmbBxSummaryCatCode.setPreferredSize(new Dimension(126, 25));
    jRdBtnSummaryPM.setFont(new java.awt.Font("SansSerif", 1, 12));
    jRdBtnSummaryPM.setPreferredSize(new Dimension(40, 17));
    jRdBtnSummaryPM.setText("pm");
    jTxtFldSummaryDeclineReason.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtFldSummaryDeclineReason.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryDeclineReason.setMinimumSize(new Dimension(225, 20));
    jTxtFldSummaryDeclineReason.setPreferredSize(new Dimension(225, 20));
    jChkBxLegal.setPreferredSize(new Dimension(130, 17));
    jChkBxLegal.setText("Legal");
    jChkBxLegal.setActionCommand("jChkBxLegal");
    jChkBxLegal.setFont(new java.awt.Font("SansSerif", 1, 12));
    jPanel2.setBorder(BorderFactory.createEtchedBorder());
    jPanel2.setLayout(gridBagLayout1);
    jPanel1.setLayout(gridBagLayout3);
    jLblSummaryPhone.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryPhone.setForeground(Color.black);
    jLblSummaryPhone.setPreferredSize(new Dimension(100, 17));
    jLblSummaryPhone.setText("Phone");
    jRdBtnSummaryAM.setPreferredSize(new Dimension(40, 17));
    jRdBtnSummaryAM.setText("am");
    jRdBtnSummaryAM.setFont(new java.awt.Font("SansSerif", 1, 12));
    jRdBtnSummaryAM.setSelected(true); // 20/12
    jTxtFldSummaryPostCode.setBorder(BorderFactory.createLoweredBevelBorder());
    jTxtFldSummaryPostCode.setMinimumSize(new Dimension(100, 20));
    jTxtFldSummaryPostCode.setPreferredSize(new Dimension(100, 20));
    jTxtFldSummaryPostCode.setFont(new java.awt.Font("SansSerif", 0, 12));
    jLblSummaryAmountSaved.setText("Amount Saved");
    jLblSummaryAmountSaved.setForeground(Color.black);
    jLblSummaryAmountSaved.setPreferredSize(new Dimension(102, 17));
    jLblSummaryAmountSaved.setFont(new java.awt.Font("SansSerif", 1, 12));
    jPnlSummaryCoy.setFont(new java.awt.Font("SansSerif", 1, 12));
    jPnlSummaryCoy.setBorder(titledBorder4);
    jPnlSummaryCoy.setLayout(gridBagLayout2);
    jLblSummaryStreetName.setFont(new java.awt.Font("SansSerif", 1, 12));
    jLblSummaryStreetName.setForeground(Color.black);
    jLblSummaryStreetName.setPreferredSize(new Dimension(100, 17));
    jLblSummaryStreetName.setText("Street Name");
    jCmbBxSummaryLossType.setBackground(Color.cyan);
    jCmbBxSummaryLossType.setFont(new java.awt.Font("SansSerif", 0, 12));
    jCmbBxSummaryLossType.setPreferredSize(new Dimension(225, 26));
    jCmbBxSummaryCauseType.setBackground(Color.cyan);
    jCmbBxSummaryCauseType.setFont(new java.awt.Font("SansSerif", 0, 12));
    jCmbBxSummaryCauseType.setPreferredSize(new Dimension(225, 26));
    jLblSummaryLossDate.setText("Loss Date");
    jLblSummaryLossDate.setForeground(Color.black);
    jLblSummaryLossDate.setPreferredSize(new Dimension(102, 17));
    jLblSummaryLossDate.setFont(new java.awt.Font("SansSerif", 1, 12));
    jTxtArLossDescription.setLineWrap(true);
    jTxtArLossDescription.setWrapStyleWord(true);
    jTxtArLossDescription.setBackground(Color.cyan);
    jTxtArLossDescription.setFont(new java.awt.Font("SansSerif", 0, 12));
    jTxtArLossDescription.setBounds(new Rectangle(124, 39, 394, 46));
    jChkBxNoBlameBonus.setPreferredSize(new Dimension(130, 17));
    jChkBxNoBlameBonus.setText("No Blame Bonus ");
    jChkBxNoBlameBonus.setFont(new java.awt.Font("SansSerif", 1, 12));
    jPanel1.setBorder(titledBorder3);
    jPanel1.setBounds(new Rectangle(23, 11, 810, 436));
    jPanel1.add(jLblSummaryCatCode, new GridBagConstraints(0, 6, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jScrPnSummaryLossDesc, new GridBagConstraints(1, 1, 6, 1, 0.9, 0.15
    ,GridBagConstraints.SOUTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    jScrPnSummaryLossDesc.getViewport().add(jTxtArLossDescription, null);
    jPanel1.add(jRdBtnSummaryPM, new GridBagConstraints(5, 0, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jTxtFldSummaryDeclineReason, new GridBagConstraints(1, 8, 2, 1, 0.1, 0.1
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryLossDesc, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.5
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryLossType, new GridBagConstraints(0, 3, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryCauseType, new GridBagConstraints(0, 4, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryDeclineReason, new GridBagConstraints(0, 8, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryLossDate, new GridBagConstraints(0, 0, 1, 1, 0.1, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jTxtFldSummaryTime, new GridBagConstraints(3, 0, 1, 1, 0.1, 0.05
    ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryTime, new GridBagConstraints(3, 0, 1, 1, 0.1, 0.05
    ,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 107, 7));
    jPanel1.add(jRdBtnSummaryAM, new GridBagConstraints(4, 0, 1, 1, 0.1, 0.05
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jCmbBxSummaryCauseType, new GridBagConstraints(1, 4, 2, 1, 0.1, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jTxtFldSummaryLossDate, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jTxtFldSummaryDateNotified, new GridBagConstraints(1, 7, 1, 1, 0.1, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jPanel2, new GridBagConstraints(0, 9, 6, 1, 1.0, 0.1
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(jChkBxNoBlameBonus, new GridBagConstraints(3, 0, 1, 1, 0.1, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(jChkBxLegal, new GridBagConstraints(4, 0, 1, 1, 0.1, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(jBtnSave, new GridBagConstraints(5, 0, 1, 1, 0.1, 0.0
    ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(jChkBxNcbLost, new GridBagConstraints(2, 0, 1, 1, 0.1, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(component1, new GridBagConstraints(1, 0, 1, 1, 0.35, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel2.add(component2, new GridBagConstraints(5, 0, 1, 1, 0.35, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jCmbBxSummaryLossType, new GridBagConstraints(1, 3, 2, 1, 0.1, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jCmbBxSummaryCatCode, new GridBagConstraints(1, 6, 2, 1, 0.1, 0.05
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jPnlSummaryCoy, new GridBagConstraints(2, 3, 4, 6, 1.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummaryPhone, new GridBagConstraints(0, 6, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummarySuburb, new GridBagConstraints(0, 3, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummaryStreetName, new GridBagConstraints(1, 2, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummaryCity, new GridBagConstraints(1, 4, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummaryPostCode, new GridBagConstraints(1, 5, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummarySuburb, new GridBagConstraints(1, 3, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummaryPostCode, new GridBagConstraints(0, 5, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummaryPhone, new GridBagConstraints(1, 6, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jTxtFldSummaryCompanyName, new GridBagConstraints(1, 0, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummaryCompanyName, new GridBagConstraints(0, 0, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummaryStreetName, new GridBagConstraints(0, 2, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPnlSummaryCoy.add(jLblSummaryCity, new GridBagConstraints(0, 4, 1, 1, 0.5, 0.16
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLblSummaryDateNotified, new GridBagConstraints(0, 7, 1, 1, 0.1, 0.05
    ,GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jBtnSummarySearch, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jTxtFldSummaryLossDate.grabFocus();
    jTxtFldSummaryLossDate.setNextFocusableComponent(jTxtFldSummaryTime);
    jTxtFldSummaryTime.setNextFocusableComponent(jRdBtnSummaryAM);
    jRdBtnSummaryAM.setNextFocusableComponent(jRdBtnSummaryPM);
    jRdBtnSummaryPM.setNextFocusableComponent(jTxtArLossDescription);
    jTxtArLossDescription.setNextFocusableComponent(jCmbBxSummaryLossType);
    jCmbBxSummaryLossType.setNextFocusableComponent(jCmbBxSummaryCauseType);
    jCmbBxSummaryCauseType.setNextFocusableComponent(jBtnSummarySearch);
    jBtnSummarySearch.setNextFocusableComponent(jCmbBxSummaryCatCode);
    jCmbBxSummaryCatCode.setNextFocusableComponent(jTxtFldSummaryDateNotified);
    jTxtFldSummaryDateNotified.setNextFocusableComponent(jTxtFldSummaryDeclineReason);
    jTxtFldSummaryDeclineReason.setNextFocusableComponent(jTxtFldSummaryCompanyName);
    jTxtFldSummaryCompanyName.setNextFocusableComponent(jTxtFldSummaryStreetName);
    jTxtFldSummaryStreetName.setNextFocusableComponent(jTxtFldSummarySuburb);
    jTxtFldSummarySuburb.setNextFocusableComponent(jTxtFldSummaryCity);
    jTxtFldSummaryCity.setNextFocusableComponent(jTxtFldSummaryPostCode);
    jTxtFldSummaryPostCode.setNextFocusableComponent(jTxtFldSummaryPhone);
    jTxtFldSummaryPhone.setNextFocusableComponent(jChkBxNcbLost);
    jChkBxNcbLost.setNextFocusableComponent(jChkBxNoBlameBonus);
    jChkBxNoBlameBonus.setNextFocusableComponent(jChkBxLegal);
    jChkBxLegal.setNextFocusableComponent(jBtnSave);
    jBtnSave.setNextFocusabl                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     &nbs

    the very simple strategy to do is to call removeAllItems() method for the 2nd combox box and then insert the contents. this is because the validate() method is not repeatedly called and so the contents are not updated immediately.

  • Who can help me :)--a problem with java program(reset problem in java )

    I do not know how to make the button reset,my program only could reset diagram but button.If any one who could help me to solve this problem.The problem is When the reset button is pressed, the image should immediately revert to the black square, and the 4 widgets listed above should show values that
    correspond to the black square.The code like this,first one is shapes:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class shapes extends JFrame {
         private JPanel buttonPanel; // panel for buttons
         private DrawPanel myPanel;  // panel for shapes
         private JButton resetButton;
        private JComboBox colorComboBox;
         private JRadioButton circleButton, squareButton;
         private ButtonGroup radioGroup;
         private JCheckBox filledButton;
        private JSlider sizeSlider;
         private boolean isShow;
         private int shape;
         private boolean isFill=true;
        private String colorNames[] = {"black", "blue", "cyan", "darkGray", "gray",
                                   "green", "lightgray", "magenta", "orange",
                                   "pink", "red", "white", "yellow"};   // color names list in ComboBox
        private Color colors[] = {Color.black, Color.blue, Color.cyan, Color.darkGray,
                              Color.gray, Color.green, Color.lightGray, Color.magenta,
                              Color.orange, Color.pink, Color.red, Color.white, Color.yellow};
         public shapes() {
             super("Draw Shapes");
             // creat custom drawing panel
            myPanel = new DrawPanel(); // instantiate a DrawPanel object
            myPanel.setBackground(Color.white);
             // set up resetButton
            // register an event handler for resetButton's ActionEvent
            resetButton = new JButton ("reset");
             resetButton.addActionListener(
              // anonymous inner class to handle resetButton events
                 new ActionListener() {
                       // draw a black filled square shape after clicking resetButton
                     public void actionPerformed (ActionEvent event) {
                             // call DrawPanel method setShowStatus and pass an parameter
                          // to decide if show the shape
                         myPanel.setShowStatus(true);
                             isShow = myPanel.getShowStatus();
                             shape = DrawPanel.SQUARE;
                         // call DrawPanel method setShape to indicate shape to draw
                             myPanel.setShape(shape);
                         // call DrawPanel method setFill to indicate to draw a filled shape
                             myPanel.setFill(true);
                         // call DrawPanel method draw
                             myPanel.draw();
                             myPanel.setFill(true);
                             myPanel.setForeground(Color.black);
                   }// end anonymous inner class
             );// end call to addActionListener
            // set up colorComboBox
            // register event handlers for colorComboBox's ItemEvent
            colorComboBox = new JComboBox(colorNames);
            colorComboBox.setMaximumRowCount(5);
            colorComboBox.addItemListener(
                 // anonymous inner class to handle colorComboBox events
                 new ItemListener() {
                     // select shape's color
                     public void itemStateChanged(ItemEvent event) {
                         if(event.getStateChange() == ItemEvent.SELECTED)
                             // call DrawPanel method setForeground
                             // and pass an element value of colors array
                             myPanel.setForeground(colors[colorComboBox.getSelectedIndex()]);
                        myPanel.draw();
                }// end anonymous inner class
            ); // end call to addItemListener
            // set up a pair of RadioButtons
            // register an event handler for RadioButtons' ItemEvent
             squareButton = new JRadioButton ("Square", true);
             circleButton = new JRadioButton ("Circle", false);
             radioGroup = new ButtonGroup();
             radioGroup.add(squareButton);
             radioGroup.add(circleButton);
            squareButton.addItemListener(
                // anonymous inner class to handle squareButton events
                new ItemListener() {
                       public void itemStateChanged (ItemEvent event) {
                           if (isShow==true) {
                                 shape = DrawPanel.SQUARE;
                                 myPanel.setShape(shape);
                                 myPanel.draw();
                   }// end anonymous inner class
             );// end call to addItemListener
             circleButton.addItemListener(
                   // anonymous inner class to handle circleButton events
                new ItemListener() {
                       public void itemStateChanged (ItemEvent event) {
                             if (isShow==true) {
                                 shape = DrawPanel.CIRCLE;
                                 myPanel.setShape(shape);
                                 myPanel.draw();
                             else
                                 System.out.println("Please click Reset button first");
                   }// end anonymous inner class
             );// end call to addItemListener
             // set up filledButton
            // register an event handler for filledButton's ItemEvent
            filledButton = new JCheckBox("Filled", true);
             filledButton.addItemListener(
              // anonymous inner class to handle filledButton events
            new ItemListener() {
                  public void itemStateChanged (ItemEvent event) {
                    if (isShow==true) {
                            if (event.getStateChange() == ItemEvent.SELECTED) {
                                  isFill=true;
                                  myPanel.setFill(isFill);
                                  myPanel.draw();
                            else {
                                isFill=false;
                                  myPanel.setFill(isFill);
                                  myPanel.draw();
                    else
                        System.out.println("Please click Reset button first");
              }// end anonymous inner class
             );// end call to addItemListener
            // set up sizeSlider
            // register an event handler for sizeSlider's ChangeEvent
            sizeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 300, 100);
            sizeSlider.setMajorTickSpacing(10);
            sizeSlider.setPaintTicks(true);
            sizeSlider.addChangeListener(
                 // anonymous inner class to handle sizeSlider events
                 new ChangeListener() {
                      public void stateChanged(ChangeEvent event) {
                          myPanel.setShapeSize(sizeSlider.getValue());
                             myPanel.draw();
                 }// end anonymous inner class
             );// end call to addChangeListener
            // set up panel containing buttons
             buttonPanel = new JPanel();
            buttonPanel.setLayout(new GridLayout(4, 1, 0, 50));
             buttonPanel.add(resetButton);
             buttonPanel.add(filledButton);
            buttonPanel.add(colorComboBox);
            JPanel radioButtonPanel = new JPanel();
            radioButtonPanel.setLayout(new GridLayout(2, 1, 0, 20));
            radioButtonPanel.add(squareButton);
            radioButtonPanel.add(circleButton);
            buttonPanel.add(radioButtonPanel);
            // attach button panel & draw panel to content panel
            Container container = getContentPane();
            container.setLayout(new BorderLayout(10,10));
            container.add(myPanel, BorderLayout.CENTER);
             container.add(buttonPanel, BorderLayout.EAST);
            container.add(sizeSlider, BorderLayout.SOUTH);
            setSize(500, 400);
             setVisible(true);
         public static void main(String args[]) {
             shapes application = new shapes();
             application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }second one is drawpanel:
    import java.awt.*;
    import javax.swing.*;
    public class DrawPanel extends JPanel {
         public final static int CIRCLE = 1, SQUARE = 2;
         private int shape;
         private boolean fill;
         private boolean showStatus;
        private int shapeSize = 100;
        private Color foreground;
         // draw a specified shape
        public void paintComponent (Graphics g){
              super.paintComponent(g);
              // find center
            int x=(getSize().width-shapeSize)/2;
              int y=(getSize().height-shapeSize)/2;
              if (shape == CIRCLE) {
                 if (fill == true){
                     g.setColor(foreground);
                      g.fillOval(x, y, shapeSize, shapeSize);
                else{
                       g.setColor(foreground);
                    g.drawOval(x, y, shapeSize, shapeSize);
              else if (shape == SQUARE){
                 if (fill == true){
                     g.setColor(foreground);
                        g.fillRect(x, y, shapeSize, shapeSize);
                else{
                        g.setColor(foreground);
                    g.drawRect(x, y, shapeSize, shapeSize);
        // set showStatus value
        public void setShowStatus (boolean s) {
              showStatus = s;
         // return showstatus value
        public boolean getShowStatus () {
              return showStatus;
         // set fill value
        public void setFill(boolean isFill) {
              fill = isFill;
         // set shape value
        public void setShape(int shapeToDraw) {
              shape = shapeToDraw;
        // set shapeSize value
        public void setShapeSize(int newShapeSize) {
              shapeSize = newShapeSize;
        // set foreground value
        public void setForeground(Color newColor) {
              foreground = newColor;
         // repaint DrawPanel
        public void draw (){
              if(showStatus == true)
              repaint();
    }If any kind people who can help me.
    many thanks to you!

    4 widgets???
    maybe this is what you mean.
    add this inside your actionPerformed method for the reset action
    squareButton.setSelected(true);
    colorComboBox.setSelectedIndex(0);
    if not be more clear in your post.

  • 1.4.2 Java Swing problems

    I have a swing application with 2 JComboBox 's, 1 JPanel (for pictures), 1 JButton and a scroll pane. Basicall the JComboBoxes have an action listener that changes the pictures when I cahnge the names. However, I would like the Jbutton when pressed to display the name chosen (from the JComboBox) and display it in the textArea. See code below.
    import javax.swing.*;
    import javax.swing.Action;
    import java.awt.event.ActionEvent;
    import  java.awt.event.ItemListener;
    import java.awt.*;
    import java.awt.event.*;
    * @author Administrator
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class choice_in2 extends JPanel implements ActionListener{
         private JLabel contender1FieldLabel;
         private JLabel contender2FieldLabel;
         private JButton runButton;
         JLabel picture1;
         JLabel picture2;
         //Text area which shows the result
         private JTextArea textArea;
         private JLabel textAreaLabel;
         public choice_in2(){
              //          Create a ChoiceField for the input of first contender
              contender1FieldLabel = new JLabel("Contender1 ",4);
              String[] contender1Strings = { "Bill", "Bob", "Don", "Michael", "John" };
              JComboBox contender1List = new JComboBox(contender1Strings);
              contender1List.setSelectedIndex(1);
              contender1List.addActionListener(new Eavesdropper1(picture1));
              //          Create a ChoiceField for the input of second contender
              contender2FieldLabel = new JLabel("Contender2 ",4);
              String[] contender2Strings = { "Philip", "Timothy", "Tom", "Kenneth", "Stone" };
              JComboBox contender2List = new JComboBox(contender2Strings);
              contender2List.setSelectedIndex(2);
              contender2List.addActionListener(new Eavesdropper2(picture2));
            //Set up the first picture.
            picture1 = new JLabel();
            picture1.setFont(picture1.getFont().deriveFont(Font.ITALIC));
            picture1.setHorizontalAlignment(JLabel.CENTER);
            updateLabel1(contender1Strings[contender1List.getSelectedIndex()]);
            picture1.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
            //Set up the second picture.
            picture2 = new JLabel();
            picture2.setFont(picture1.getFont().deriveFont(Font.ITALIC));
            picture2.setHorizontalAlignment(JLabel.CENTER);
            updateLabel2(contender2Strings[contender2List.getSelectedIndex()]);
            picture2.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
            //The preferred size is hard-coded to be the width of the
            //widest image and the height of the tallest image + the border.
            //A real program would compute this.
            picture1.setPreferredSize(new Dimension(200, 220+10));
            picture2.setPreferredSize(new Dimension(200, 220+10));
              // Create a JButton that will compute
              runButton = new JButton("Compute");
              runButton.addActionListener(new Eavesdropper3(textArea));
              // Create a JTextArea that will display the results
              textAreaLabel = new JLabel("Results");       
              textArea = new JTextArea(10,70);
              textArea.setFont(new Font("Courier",Font.PLAIN,12));
              JScrollPane scrollPane =  new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
              textArea.setEditable(false);
            //Lay out the demo.
            add(contender1List, BorderLayout.WEST);
            add(picture1, BorderLayout.WEST);
            add(contender2List, BorderLayout.EAST);       
            add(picture2, BorderLayout.EAST);
            add(runButton, BorderLayout.EAST);
            add(textAreaLabel, BorderLayout.SOUTH);
            add(scrollPane, BorderLayout.SOUTH);
            setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
        /** Listens to the combo box. */
        public void actionPerformed(ActionEvent e) {
        public void updateLabel1(String name1) {
            ImageIcon icon1 = createImageIcon( name1 + ".jpg");
            picture1.setIcon(icon1);
            picture1.setToolTipText("A drawing of a " + name1.toLowerCase());
            if (icon1 != null) {
                picture1.setText(null);
            } else {
                picture1.setText("Image not found");
        public void updateLabel2(String name2) {
             ImageIcon icon2 = createImageIcon( name2 + ".jpg");
            picture2.setIcon(icon2);
            picture2.setToolTipText("A drawing of a " + name2.toLowerCase());
            if (icon2 != null) {
               picture2.setText(null);
            } else {
                picture2.setText("Image not found");
        /** Returns an ImageIcon, or null if the path was invalid. */
        public ImageIcon createImageIcon(String path) {
            java.net.URL imgURL = choice_in2.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
        class Eavesdropper2 implements ActionListener {
            JLabel myTextArea;
            public Eavesdropper2(JLabel ta) {
                 myTextArea = ta;
            public void actionPerformed(ActionEvent e) {
                JComboBox contender2List = (JComboBox)e.getSource();
                String contender2ListName = (String)contender2List.getSelectedItem();
                updateLabel2(contender2ListName);
                Eavesdropper3 code;
                code = new Eavesdropper3(contender2ListName);
        class Eavesdropper1 implements ActionListener {
            JLabel myTextArea;
            public Eavesdropper1(JLabel tt) {
                 myTextArea = tt;
            public void actionPerformed(ActionEvent e) {
                JComboBox contender1List = (JComboBox)e.getSource();
                String contender1ListName = (String)contender1List.getSelectedItem();
                updateLabel1(contender1ListName);
        class Eavesdropper3  implements ActionListener  {
             String contender22;
            JTextArea myTextArea;
            public Eavesdropper3(JTextArea bb) {
                 myTextArea = bb;
            public Eavesdropper3(String contender2ListName){
                 contender22 = contender2ListName;
               * @return Returns the contender22.
              public String getContender22() {
                   return contender22;
            public void actionPerformed(ActionEvent e) {
                 textArea.setText("Wild Test");
                 textArea.append("\n      OUTCOME    \n\n " +getContender22());
    }

    weebib
    We are using Windows XP , Nvidia graphics card, with Multiview. I hope the problem is not specific to the platform.
    It is reproducible with 1.4.2 and absent in 1.4.1
    camickr
    I am new to this forum. didn't know about code blocks.

  • Problem with Combo Box in a Dialog Box

    I have a dialog box that includes a combo box.
    For some reason the combo box shows up under the first text box. In other words, the combo box is not separate from the first field. It has the following:
    ComboBox with Sequence showing, then Enter Identifyer
    Textbox URL
    Textbox Enter Resource 1
    Textbox Enter Resource 2
    Textbox Enter Resource 3
    Textbox Enter Resource 4
    Textbox Enter Resource 5
    It's putting the combo box in the first text field...it should be
    ComboBox with Sequence showing
    URL Textbox
    Enter Identifyer Textbox
    Enter Resource 1 Textbox
    Enter Resource 2 Textbox...
    Here is my code:
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import dl.*;
    * Dialog to enter container information
    public class AddContainer extends JDialog {
    private JTextField valueBox1;
    private JTextField valueBox2;
    private JTextField valueBox3;
    private JTextField valueBox4;
    private JTextField valueBox5;
    public String value1;
    public String value2;
    public String value3;
    public String value4;
    public String value5;
    private JTextField identifyerBox;
    private JTextField URLBox;
    private JTextField attrBox;
    public String identifyer;
    public String URL;
    public int choice;
    * Constructor.
    public AddContainer(Frame parent) {
    super(parent, "Add Container", true);
    JPanel pp = new JPanel(new DialogLayout2());
    pp.setBorder(new CompoundBorder(
    new EtchedBorder(EtchedBorder.RAISED),
    new EmptyBorder(5,5,5,5)));
    String[] ContStrings = {  "Sequence", "Bag", "Alternative" };
    // Add action listener.
    ActionListener contlst = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    JComboBox cb = (JComboBox)e.getSource();
    int choice = (int)cb.getSelectedIndex();
    //Create the combo box, select the item at index 0.
    //Indices start at 0, so 2 specifies the Alternative
    JComboBox ContList = new JComboBox(ContStrings);
    ContList.setSelectedIndex(0);
    ContList.addActionListener(contlst);
    //Add combo box to panel.
    pp.add(ContList);
    pp.add(new JLabel("Enter Identifyer"));
    identifyerBox = new JTextField(16);
    pp.add(identifyerBox);
    pp.add(new JLabel("URL"));
    URLBox = new JTextField(16);
    pp.add(URLBox);
    pp.add(new JLabel("Enter Resource 1"));
    valueBox1 = new JTextField(25);
    pp.add(valueBox1);
    pp.add(new JLabel("Enter Resource 2"));
    valueBox2 = new JTextField(25);
    pp.add(valueBox2);
    pp.add(new JLabel("Enter Resource 3"));
    valueBox3 = new JTextField(25);
    pp.add(valueBox3);
    pp.add(new JLabel("Enter Resource 4"));
    valueBox4 = new JTextField(25);
    pp.add(valueBox4);
    pp.add(new JLabel("Enter Resource 5"));
    valueBox5 = new JTextField(25);
    pp.add(valueBox5);
    JPanel p = new JPanel(new DialogLayout2());
    p.setBorder(new EmptyBorder(10, 10, 10, 10));
    p.add(pp);
    ActionListener lst = new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    identifyer = identifyerBox.getText();
    URL = URLBox.getText();
    value1 = valueBox1.getText();
    value2 = valueBox2.getText();
    value3 = valueBox3.getText();
    value4 = valueBox4.getText();
    value5 = valueBox5.getText();
    dispose();
    JButton saveButton = new JButton("ADD");
    saveButton.addActionListener(lst);
    getRootPane().setDefaultButton(saveButton);
    getRootPane().registerKeyboardAction(lst,
    KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
    JComponent.WHEN_IN_FOCUSED_WINDOW);
    p.add(saveButton);
    JButton cancelButton = new JButton("Cancel");
    lst = new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    dispose();
    cancelButton.addActionListener(lst);
    getRootPane().registerKeyboardAction(lst,
    KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
    JComponent.WHEN_IN_FOCUSED_WINDOW);
    p.add(cancelButton);
    getContentPane().add(p, BorderLayout.CENTER);
    pack();
    setResizable(false);
    setLocationRelativeTo(parent);

    Seems the problem is in your DialogLayout2 class which must be in package dl. I tried a grid layout and got something that looks like what you described. I laid out pp with a gridbag layout.
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    //import dl.*;
    * Dialog to enter container information
    public class jello extends JDialog {
      private JTextField valueBox1;
      private JTextField valueBox2;
      private JTextField valueBox3;
      private JTextField valueBox4;
      private JTextField valueBox5;
      public String value1;
      public String value2;
      public String value3;
      public String value4;
      public String value5;
      private JTextField identifyerBox;
      private JTextField URLBox;
      private JTextField attrBox;
      public String identifyer;
      public String URL;
      public int choice;
      * Constructor.
      public jello(JFrame parent) {
        super(parent, "Add Container", true);
        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        JPanel pp = new JPanel(gridbag);
                            //(new GridLayout(0,2));
                            //(new DialogLayout2());
        pp.setBackground(Color.red);
        pp.setBorder(
          new CompoundBorder(
            new EtchedBorder(EtchedBorder.RAISED),
            new EmptyBorder(5,5,5,5)));
        String[] ContStrings = { "Sequence", "Bag", "Alternative" };
        // Add action listener.
        ActionListener contlst = new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox)e.getSource();
            int choice = (int)cb.getSelectedIndex();
        //Create the combo box, select the item at index 0.
        //Indices start at 0, so 2 specifies the Alternative
        JComboBox ContList = new JComboBox(ContStrings);
        ContList.setSelectedIndex(0);
        ContList.addActionListener(contlst);
        //Add combo box to panel.
        gbc.insets = new Insets(2,2,2,2);
        gbc.anchor = gbc.WEST;
        gbc.gridwidth = gbc.REMAINDER;
        pp.add(ContList, gbc);
        gbc.anchor = gbc.EAST;
        gbc.gridwidth = gbc.RELATIVE;
        pp.add(new JLabel("Enter Identifyer"), gbc);
        identifyerBox = new JTextField(16);
        gbc.anchor = gbc.WEST;
        gbc.gridwidth = gbc.REMAINDER;
        pp.add(identifyerBox, gbc);
        gbc.anchor = gbc.EAST;
        gbc.gridwidth = gbc.RELATIVE;
        pp.add(new JLabel("URL"), gbc);
        URLBox = new JTextField(16);
        gbc.anchor = gbc.WEST;
        gbc.gridwidth = gbc.REMAINDER;
        pp.add(URLBox, gbc);
        gbc.anchor = gbc.CENTER;
        gbc.gridwidth = gbc.RELATIVE;
        pp.add(new JLabel("Enter Resource 1"), gbc);
        valueBox1 = new JTextField(25);
        gbc.gridwidth = gbc.REMAINDER;
        pp.add(valueBox1, gbc);
        gbc.gridwidth = gbc.RELATIVE;
        pp.add(new JLabel("Enter Resource 2"), gbc);
        valueBox2 = new JTextField(25);
        gbc.gridwidth = gbc.REMAINDER;
        pp.add(valueBox2, gbc);
        gbc.gridwidth = gbc.RELATIVE;
        pp.add(new JLabel("Enter Resource 3"), gbc);
        valueBox3 = new JTextField(25);
        gbc.gridwidth = gbc.REMAINDER;
        pp.add(valueBox3, gbc);
        gbc.gridwidth = gbc.RELATIVE;
        pp.add(new JLabel("Enter Resource 4"), gbc);
        valueBox4 = new JTextField(25);
        gbc.gridwidth = gbc.REMAINDER;
        pp.add(valueBox4, gbc);
        gbc.gridwidth = gbc.RELATIVE;
        pp.add(new JLabel("Enter Resource 5"), gbc);
        valueBox5 = new JTextField(25);
        gbc.gridwidth = gbc.REMAINDER;
        pp.add(valueBox5, gbc);
        JPanel p = new JPanel();//(new DialogLayout2());
        p.setBackground(Color.blue);
        p.setBorder(new EmptyBorder(10, 10, 10, 10));
        p.add(pp);
        ActionListener lst = new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            identifyer = identifyerBox.getText();
            URL = URLBox.getText();
            value1 = valueBox1.getText();
            value2 = valueBox2.getText();
            value3 = valueBox3.getText();
            value4 = valueBox4.getText();
            value5 = valueBox5.getText();
            dispose();
        JButton saveButton = new JButton("ADD");
        saveButton.addActionListener(lst);
        getRootPane().setDefaultButton(saveButton);
        getRootPane().registerKeyboardAction(lst,
          KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
          JComponent.WHEN_IN_FOCUSED_WINDOW);
        p.add(saveButton);
        JButton cancelButton = new JButton("Cancel");
        lst = new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            dispose();
        cancelButton.addActionListener(lst);
        getRootPane().registerKeyboardAction(lst,
          KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
          JComponent.WHEN_IN_FOCUSED_WINDOW);
        p.add(cancelButton);
        parent.getContentPane().add(p, BorderLayout.CENTER);
        parent.pack();
        parent.setResizable(false);
    //    setLocationRelativeTo(parent);
        parent.setVisible(true);
      public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        new jello(frame);
        frame.setLocation(0,200);
    }

  • Problem with JTableHeader Render

    Hello,
    I am using JTableHeader renderer as below:
    TableHeaderRender headerRender;
    fixedModel.addColumn("");
                   TableColumnModel colModel = Table.getColumnModel();
                   for(int i=0; i<colModel.getColumnCount(); i++ )
                        colModel.getColumn(i).setHeaderRenderer(headerRender);
    And the renderer is as below:
    class FixedTableHeaderRender extends DefaultTableCellRenderer
              JLabel label = null;
              String[] selectList= {"Item1","item 2", Item 3", "Item 4"};
              JComboBox ColStatBox= new JComboBox(selectList);
    public FixedTableHeaderRender()
    super();
    label = new JLabel();
    label.setOpaque(true);
    label.setBorder(new LineBorder(Color.black));
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.setVerticalAlignment(SwingConstants.CENTER);
    ColStatBox.setSelectedIndex(0);
    ColStatBox.setEnabled(true);
    ColStatBox.setAutoscrolls(true);
    ColStatBox.addActionListener(new ActionHandler(){
    public Component getTableCellRendererComponent(JTable table, Object value,
              boolean isSelected,boolean hasFocus, int row,int column)
         Component comp= null;
         if(column==0)
              comp=ColStatBox;
         else
              label.setText("100");
              comp=label;
         return comp;
    Now in this for First column header the JComboBox is displayed and for rest of the column the label is displayed.
    But in this, the JComboBox is not working i.e. I am not able the browse through the list. If I want to select any item (Item 4), its not allowing me to select.
    How to make it enable and function normally?
    Do reply.
    Thanks and regards,
    Sheetal

    I've amended your code as shown. Some points:
    1) Not sure what all the scroll bar stuff is for, I've removed it.
    2) The method DefaultTableModel.addColumn is too crude. If you look at the JDK source it calls fireTableStructureChanged(). This has the effect of recreating the column model, which in turn resets all the widths. It will also clear out any renderers/editors you had set up within the TableColumn instances inside the TableColumnModel (if any). Those setup by column class would be OK (I think).
    I didn't look into the remainder of your problem, hopefully you are OK now...
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JScrollBar;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.*;
    import javax.swing.table.DefaultTableModel;
    public class MyJTable extends JFrame
    DefaultTableModel model;
    JButton addBtn;
    JTable table;
    JScrollBar scrollBar;
    JScrollPane scrollPane;
         public MyJTable()
              getContentPane().setLayout(new BorderLayout());
              Object[] header= {"1", "2"};
              model= new DefaultTableModel();
              model.setDataVector(null,header);
               table = new JTable(model);
               table.getTableHeader().setReorderingAllowed(false);
               table.getTableHeader().setResizingAllowed(true);
               table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
               scrollBar=new JScrollBar();
              scrollBar.setOrientation(1);
              scrollBar.setBlockIncrement(1);
              scrollBar.setMinimum(0);
              scrollBar.setMaximum(50);
              scrollBar.setUnitIncrement(1);
              scrollBar.setVisibleAmount(1);
              table.add(scrollBar);
              scrollPane=new JScrollPane(table);
              scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
               addBtn=new JButton("Add Column");
               addBtn.addActionListener(new ActionHandler());
               getContentPane().add(scrollPane, BorderLayout.CENTER);
               getContentPane().add(addBtn, BorderLayout.SOUTH);
         class ActionHandler implements ActionListener
              //@Override
              public void actionPerformed(ActionEvent ae)
                   // TODO Auto-generated method stub
                   if(ae.getSource()==addBtn)
                        //model=(DefaultTableModel)table.getModel();
                        //model.addColumn("A");
                        //model.fireTableStructureChanged();
                        TableColumnModel tcm = table.getColumnModel();
                        TableColumn newCol = new TableColumn();
                        newCol.setHeaderValue("A");
                        tcm.addColumn(newCol);
          * @param args
         public static void main(String[] args)
              MyJTable frame = new MyJTable();
                  frame.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  frame.setSize( 300, 400 );
                  frame.setVisible(true);
    }

  • Swing JComboBox causes scrolling problems in applet

    I have an applet with a JPanel that contains a JComboBox that lists font selections for a JTextPane in a JPanel below it. It contains about 12 items, of which only five are visible at a time. If I choose any of the first five and scroll the page on which the applet is running, there are no issues. However, if I scroll the page after scrolling down the list to the sixth item, regardless of whether or not I actually select it, it causes the graphics in the applet to corrupt. The JComboBox code is:
    private JComboBox getFontFaceCB() {
                   String[] fontNames = new String[fontlist.length];
                   for (int i = 0; i < fontlist.length; i++){
                        fontNames[i] = fontlist.getFamily();
                   if (fontFaceCB == null) {
                        fontFaceCB = new JComboBox(fontNames);
                        fontFaceCB.setBackground(Color.white);
                        fontFaceCB.setPreferredSize(new Dimension(150, 30));
                        fontFaceCB.setMaximumRowCount(5);
                        fontFaceCB.setSelectedIndex(0);
                        fontFaceCB.addItemListener(new java.awt.event.ItemListener() {
                             public void itemStateChanged(java.awt.event.ItemEvent e) {
                                            currentFont = fontlist[fontFaceCB.getSelectedIndex()];
                                            StyleConstants.setFontFamily(textStyles, currentFont.getFamily());
                                            jTextPane.setCharacterAttributes(textStyles, true);
                                            viewWidget.repaint();
                   return fontFaceCB;
              }This also happens if I set the default index to something that one must scroll down to reach (e.g. the sixth index) I was wondering if anyone else has come across this issue and has any idea as to how this may be resolved.
    Also, if the window is minimized, resized, etc. the graphics also corrupt, but only after the aforementioned condition.
    Edited by: BANZ111 on Dec 12, 2007 3:59 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I have found the solution:
    I had lightweight components intertwined with heavyweight ones, which, until now, I never regarded as being a possible source of problems. Apparently, when you scroll down a JComboBox, it changes from light to heavy weight? At any rate, I found this with a lot of other useful tips here:
    http://72.5.124.55/javase/6/webnotes/trouble/TSG-Desktop/html/gchzf.html#gdldq
    Perhaps this can be of use to anyone else who gets a similar problem.

  • KeyReleased event problems

    Hi everybody,
    i have a JTable and what I want to is that when the user type something in the TextField the table will show the names of the company that start with the letter that the user typed. But the problem is that each time the user type the event executes 2 times, this is the code:
    private void txt_searchCompanyKeyReleased(java.awt.event.KeyEvent evt) {
    TableModel model = jt_Company.getModel();
    ArrayList<String[]> dataArray = new ArrayList<String[]>();
    String[] data = new String[ jt_Company.getRowCount() ];
    String s = txt_searchCompany.getText();
    System.out.println("Cantidad de filas: " + jt_Company.getRowCount()+ "\nCantidad de col: " + jt_Company.getColumnCount());
    for(int i = 0; i < jt_Company.getRowCount(); i++)
       for(int j = 0; j < model.getColumnCount(); j++)
           if(model.getValueAt(i, 1).toString().startsWith(s) == true)
             data = model.getValueAt(i, j).toString();
             dataArray.add(data);
              System.out.println(" " + data[0] + "Tamano de ArrayList: " + data.  length);
    jt_Company.setModel(new Business.CompanyTable(dataArray));
    }//End of the method
    the method compares very well the string and the name of the companies in each row, but as mention before the method do it 2 times that means that the string array will the double of rows.
    How can I do to make the event execute only one time
    Thanks a lot.......

    Hi,
    KeyListener is not probably a good idea for you. You should use DocumentListener. for Example:
    jTextFieldIP.getDocument().addDocumentListener(new DocumentListener()
       public void changeUpdate(DocumentEvent e){}
       public void insertUpdate(DocumentEvent e)
           try
               jListCode.setSelectedIndex(Integer.parseInt(jTextFieldIP.getText()));
            catch(NumberFormatException ne)
                JOptionPane.showMessageDialog(null, "Only numbers in this field please.");
       public void removeUpdate(DocumentEvent e)
           insertUpdate(e);
    } );

  • Problem, change the language with dynamic text

    I am looking for a way to change simply the language of my flash animation
    I work with flash cs4
    of course I got Mylocale.as:
    import mx.lang.Locale;
    class MyLocale extends mx.lang.Locale {
    static function start():Void {  
    var langCode:String = xmlLang;
    currentXMLMapIndex = 0;
    xmlDoc.load(xmlMap[langCode][0]);
    static function setXMLLang(langCode:String):Void {
    xmlLang = langCode;
    and different xml files in the same folder than my swf file
    in string , I ticked : "replace  strings automatically during the execution"
      with a default language (I am wondering if the problem is not from there)
      if I tick: "replace strings manually using the scene language " or "replace strings via actionscript"
    my code does not work.
      then I kept: "replace strings automatically during the execution"
    in my flash animation I have several scenes (pages)
    p1, p2, p3, p4
    in p1
    I created a language bar
    then 2 layers inside
    Layer--action:
    langListener = new Object();
    langListener.change = function(eventObj) {
    var target = eventObj.target;
    var newLang = target.selectedItem.data;
    MyLocale.setXMLLang(newLang);
    MyLocale.start();
    lang_cb.addEventListener("change", langListener);
    // Force Japanese
    lang_cb.selectedIndex = 1;
    lang_cb.dispatchEvent({type:"change"});
    Layer--language ex Fr:
    // Forces combobox to have the correct value
    on (release) {
    var component = _parent.lang_cb;
    for (var i=0; i< component.length; i++) {
    var item = component.getItemAt(i);
    if (item.data == "fr") {
    component.setSelectedIndex(i);
    component.dispatchEvent({type:"change"});
    break;
    ex Ja :
    // Forces combobox to have the correct value
    on (release) {
    var component = _parent.lang_cb;
    for (var i=0; i< component.length; i++) {
    var item = component.getItemAt(i);
    if (item.data == "ja") {
    component.setSelectedIndex(i);
    component.dispatchEvent({type:"change"});
    break;
    When I change the language in p1 , the language is also modified in p2, p3 and p4
    however , after a navigation in p2, p3 and p4 , once I come back in p1 , the default language is back automatically although I did not touch the language bar!!
    I don't know how to solve the problem
    to my mind , the script reset itself each time I come back on p1
    is there a way to keep the saved settings even when I am back on p1 until I modify manually again the language bar
    thanks a lot

    I am looking for a way to change simply the language of my flash animation
    I work with flash cs4
    of course I got Mylocale.as:
    import mx.lang.Locale;
    class MyLocale extends mx.lang.Locale {
    static function start():Void {  
    var langCode:String = xmlLang;
    currentXMLMapIndex = 0;
    xmlDoc.load(xmlMap[langCode][0]);
    static function setXMLLang(langCode:String):Void {
    xmlLang = langCode;
    and different xml files in the same folder than my swf file
    in string , I ticked : "replace  strings automatically during the execution"
      with a default language (I am wondering if the problem is not from there)
      if I tick: "replace strings manually using the scene language " or "replace strings via actionscript"
    my code does not work.
      then I kept: "replace strings automatically during the execution"
    in my flash animation I have several scenes (pages)
    p1, p2, p3, p4
    in p1
    I created a language bar
    then 2 layers inside
    Layer--action:
    langListener = new Object();
    langListener.change = function(eventObj) {
    var target = eventObj.target;
    var newLang = target.selectedItem.data;
    MyLocale.setXMLLang(newLang);
    MyLocale.start();
    lang_cb.addEventListener("change", langListener);
    // Force Japanese
    lang_cb.selectedIndex = 1;
    lang_cb.dispatchEvent({type:"change"});
    Layer--language ex Fr:
    // Forces combobox to have the correct value
    on (release) {
    var component = _parent.lang_cb;
    for (var i=0; i< component.length; i++) {
    var item = component.getItemAt(i);
    if (item.data == "fr") {
    component.setSelectedIndex(i);
    component.dispatchEvent({type:"change"});
    break;
    ex Ja :
    // Forces combobox to have the correct value
    on (release) {
    var component = _parent.lang_cb;
    for (var i=0; i< component.length; i++) {
    var item = component.getItemAt(i);
    if (item.data == "ja") {
    component.setSelectedIndex(i);
    component.dispatchEvent({type:"change"});
    break;
    When I change the language in p1 , the language is also modified in p2, p3 and p4
    however , after a navigation in p2, p3 and p4 , once I come back in p1 , the default language is back automatically although I did not touch the language bar!!
    I don't know how to solve the problem
    to my mind , the script reset itself each time I come back on p1
    is there a way to keep the saved settings even when I am back on p1 until I modify manually again the language bar
    thanks a lot

Maybe you are looking for

  • Time Capsule disk access SLOW!   2TB - Dual band

    I have a Time Capsule (2TB, Dual Band, Firmare at 7.4.2) Its been working like a dream, backing up 3 Macs for the last 8 months. I also use it for connecting two or three other disks via USB and then making those accessible over the LAN, and there is

  • Is there a way to save files in two (2) locations at once?

    Hi everyone. I am a devoted mac user, but I am significantly less computer-savvy than most other mac users I know. I recently upgraded my 2.66 GHz quad core mac pro to have three 1TB hard drives. I want to use one of those drives for my FCP cache, an

  • Change color on clip art

    With MS products you can change the color of a clip art item. Can you do it in Pages??? Or anything MAC?

  • RE: (forte-users) Killing the Nones - solved

    Thanks to all of you who helped ... this pex file works great. Allan -----Original Message----- From: kelsey.petrychynsasktel.sk.ca [SMTP:kelsey.petrychynsasktel.sk.ca] Sent: Thursday, August 24, 2000 9:51 AM To: Pomeroy, Allan Cc: kamranaminyahoo.co

  • RPE-02062:        How to abort a workflow process?

    Hi all, I have a problem with a process flow I'm trying to deploy then i get following error message. I can not abort it with Oracle Workflow Monitor because I don't have it installed. RPE-02062: ItemType RAIN_PKG cannot be dropped as it has running