The information in this article applies to:
When making a call to TabPage.setSelectedTab from within an OnSelectedIndexChanged event handler of the parent TabControl, the focus will first go to the user-selected index before returning to the index value set in the setSelectedTab call. In addition, when returning to the index set in code by the setSelectedTab call, the children components of the set TabPage will not be visible and Control.setVisible(true) must be used, causing a noticeable flicker.
To work around this problem, call Control.setVisible(true) on the TabPage after the setSelectedTab call is made.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
This bug was corrected in Microsoft® Visual Studio® 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:
Q194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why
Q194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed
Results: When setting the TabPage back to the one that had invalid data in its Edit box, the Edit box will not be visible. Call TabControl.setVisible(true) to work around this problem.
import com.ms.wfc.app.*; import com.ms.wfc.core.*; import com.ms.wfc.ui.*; import com.ms.wfc.html.*; import com.ms.win32.*; public class Form1 extends Form { TabPage lastPage; public Form1() { super(); initForm(); lastPage = tabPage1; } public void dispose() { super.dispose(); components.dispose(); } private void onSelectedIndexChanged(Object source, Event e) { Control[] ctrls = lastPage.getControls(); for (int i = 0; i < ctrls.length; i++) { if (ctrls[i] instanceof Edit) { Edit edit = (Edit)ctrls[i]; if (edit.getText().equalsIgnoreCase("Valid Data")) { lastPage = tabControl1.getSelectedTab(); return; } tabControl1.setSelectedTab(lastPage); break; } } } /** * NOTE: The following code is required by the Visual J++ form * designer. It can be modified using the form editor. Do not * modify it using the code editor. */ Container components = new Container(); TabControl tabControl1 = new TabControl(); TabPage tabPage1 = new TabPage(); TabPage tabPage2 = new TabPage(); TabPage tabPage3 = new TabPage(); Edit edit1 = new Edit(); Button button1 = new Button(); Button button2 = new Button(); Edit edit2 = new Edit(); Button button3 = new Button(); Edit edit3 = new Edit(); private void initForm() { this.setText("Form1"); this.setAutoScaleBaseSize(new Point(5, 13)); this.setClientSize(new Point(546, 261)); tabControl1.setLocation(new Point(16, 8)); tabControl1.setSize(new Point(504, 232)); tabControl1.setTabIndex(0); tabControl1.setText("tabControl1"); tabControl1.setSelectedIndex(2); tabControl1.addOnSelectedIndexChanged (new EventHandler(this.onSelectedIndexChanged)); tabPage1.setLocation(new Point(4, 25)); tabPage1.setSize(new Point(496, 203)); tabPage1.setTabIndex(0); tabPage1.setText("tabPage1"); tabPage2.setLocation(new Point(4, 25)); tabPage2.setSize(new Point(496, 203)); tabPage2.setTabIndex(1); tabPage2.setText("tabPage2"); tabPage3.setLocation(new Point(4, 25)); tabPage3.setSize(new Point(496, 203)); tabPage3.setTabIndex(2); tabPage3.setText("tabPage3"); edit1.setLocation(new Point(8, 8)); edit1.setSize(new Point(448, 20)); edit1.setTabIndex(0); edit1.setText("edit1"); button1.setLocation(new Point(8, 168)); button1.setSize(new Point(75, 23)); button1.setTabIndex(1); button1.setText("button1"); button2.setLocation(new Point(8, 168)); button2.setSize(new Point(75, 23)); button2.setTabIndex(0); button2.setText("button2"); edit2.setLocation(new Point(8, 8)); edit2.setSize(new Point(424, 20)); edit2.setTabIndex(1); edit2.setText("edit2"); button3.setLocation(new Point(8, 168)); button3.setSize(new Point(75, 23)); button3.setTabIndex(0); button3.setText("button3"); edit3.setLocation(new Point(8, 8)); edit3.setSize(new Point(416, 20)); edit3.setTabIndex(1); edit3.setText("edit3"); this.setNewControls(new Control[] { tabControl1}); tabControl1.setNewControls(new Control[] { tabPage1, tabPage2, tabPage3}); tabPage1.setNewControls(new Control[] { button1, edit1}); tabPage2.setNewControls(new Control[] { edit2, button2}); tabPage3.setNewControls(new Control[] { edit3, button3}); } public static void main(String args[]) { Application.run(new Form1()); } }
For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, please see the following pages on the Microsoft Technical Support site:
http://support.microsoft.com/support/visualj/
http://support.microsoft.com/support/java/