Has anyone noticed a similar strange problem? The Choicecontrol component moves itself as the contents of it are changed! The whole story goes like this:
I have two Choicecontrol components on a frame. The first one (chTeam) is used for selecting a team and the other one is used for selecting an employee (chEmployee) from the selected team. Obviously, these components get their contents from a database, which in my case is Interbase 5.
As the selection from chTeam is made, a parameterized query is executed, the items of the chEmployee-Choicecontrol are removed and new items are set to that component. Now, without any visible reason, the chEmployee-Choicecontrol moves on a frame about 10 pixels left and about
the same amount upwards!!! I have the source code below, if it helps. I am using JBuilder2 Client/Server version with InterBase5 database. I have tried with JBCL's and AWT's Choicecontrols with the same results.
All the help is highly appreciated!
regards,
Tapio Martimo
public void addTeamEmps()
{
chEmployee.removeAll();
try
{
dMtask1.qryEmployees.close();
dMtask1.paramTeamname.setString("teamname", (String)chTeam.getSelectedItem());
dMtask1.qryEmployees.refresh();
dMtask1.qryEmployees.open();
for (int i = 0; i < dMtask1.qryEmployees.getRowCount(); i++)
{
chEmployee.add((String)dMtask1.qryEmployees.getString("FULLNAME"));
dMtask1.qryEmployees.next();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
DAVID DONG
July 29th, 1999, 06:55 AM
I wander if this would be help for you.
first, you can remove the database related statement.
Then, you can add some choice item string in your method directly.and run it, to see if it works.
Second, you can print all the result of you database command by use your code in your method. this can give the test if the database related command is right exec.
so far. hope helps.
This is from david dong.
tamart00
July 29th, 1999, 08:52 AM
Hi again!
Thanks for your suggestions. That lead me forward a little bit, but not totally.
I have been digging into this problem now for the whole day and I have discovered that in the Applet window, the items of the Choicecontrol-component can be changed without this weird jumping behavior. BUT, in the frame dialog, which is opened from the applet, the problem occurs consistently. It does not matter, if the item contents (Strings) are retrieved from a database or if they are given as class variables etc. I've included a small sample of this problem in this reply. If you are interested, copy and compile this and see it for yourself.
regards,
Tapio Martimo
here is the code for the applet. In this, the behavior of the components is normal...
//import com.sun.java.swing.UIManager;
public class applet1 extends JApplet {
boolean isStandalone = false;
Choice ch1 = new Choice();
Button button1 = new Button();
String[] first = {"first", "second", "third"};
String[] second = {"Changedfirst", "Changedsecond", "Changedthird", "and the last one"};
boolean current = true;
Button button2 = new Button();
Frame1 f1 = new Frame1();
GridBagLayout gridBagLayout1 = new GridBagLayout();
//Get a parameter value
private void jbInit() throws Exception {
this.setSize(400,300);
this.getContentPane().setLayout(gridBagLayout1);
button1.setLabel("change values in the control");
button2.setLabel("show the frame");
button2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
button2_mouseClicked(e);
}
});
button1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
button1_mouseClicked(e);
}
});
this.getContentPane().add(ch1, new GridBagConstraints2(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(130, 81, 0, 8), 164, 0));
this.getContentPane().add(button1, new GridBagConstraints2(1, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(118, 109, 4, 5), 0, 0));
this.getContentPane().add(button2, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(118, 3, 4, 0), 17, 0));
// for (int i = 0; i < first.length; i++)
// ch1.add(first[i]);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
void button1_mouseClicked(MouseEvent e) {
if (current)
{
ch1.removeAll();
current = false;
for (int i = 0; i < first.length; i++)
ch1.add(first[i]);
}
else
{
ch1.removeAll();
current = true;
for (int i = 0; i < second.length; i++)
ch1.add(second[i]);
}
}
void button2_mouseClicked(MouseEvent e) {
if (!f1.isShowing())
f1.show();
}
}
and here comes the frame: in this, the problem arises...
public class Frame1 extends JFrame {
Choice ch1 = new Choice();
String[] first = {"first", "second", "third"};
String[] second = {"Changedfirst", "Changedsecond", "Changedthird", "and the last one"};
boolean current = true;
Button button1 = new Button();
GridBagLayout gridBagLayout1 = new GridBagLayout();
private void jbInit() throws Exception {
this.getContentPane().setLayout(gridBagLayout1);
button1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
button1_mouseClicked(e);
}
});
button1.setLabel("change the values");
this.getContentPane().add(ch1, new GridBagConstraints2(0, 1, 1, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(82, 110, 140, 0), 127, 0));
this.getContentPane().add(button1, new GridBagConstraints2(0, 0, 2, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 0, 0, 0), 278, 0));
this.resize(450,300);
}
void button1_mouseClicked(MouseEvent e) {
if (current)
{
ch1.removeAll();
current = false;
for (int i = 0; i < first.length; i++)
ch1.add(first[i]);
}
else
{
ch1.removeAll();
current = true;
for (int i = 0; i < second.length; i++)
ch1.add(second[i]);
}
}
}
DAVID DONG
August 5th, 1999, 11:23 AM
Had seen your code, but I don't install the Swing support on my IE5.0
And I did not got the borland,jbcl.layout Package.
So I write a simple code too, but it works. Then I thind the problem
you encounter may be one of the follow reasons :
1.you use the JApplet and JFrame
2.you use the borland.jbcl.layout.*;
3.the IE version difference (or may be you use other kind Broswer).
////the follow is the my applet code