-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0, 1.3.0
-
merlin
-
generic, x86
-
generic, windows_nt
Name: krT82822 Date: 11/09/99
11/9/99 eval1127@eng -- reproducible in kestrel-RA (1.3.0 build "I") with the SwingSet demo.
--------------
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
Compile and run the following test program. Select a tree node, then select
the menu opton for LAF change. Note the tree selection is lost when the
components repaint after the UI change.
// add your custom import statements here
import javax.swing.*;
import javax.swing.tree.*;
class Form1 extends javax.swing.JFrame implements
java.awt.event.WindowListener, java.awt.event.ActionListener
{
public static void main(String args[])
{
CreateMainForm();
}
public Form1 CreateMainForm()
{
Form1 form = new Form1();
try {
form.create();
}
catch ( java.lang.Exception __e ) {
__e.printStackTrace();
}
return form;
}
public java.awt.Rectangle DURectangle( int x, int y, int w, int h )
{
String alphabet
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
java.awt.FontMetrics fm = getFontMetrics( getFont() );
double fw = ( fm != null ) ? ( fm.stringWidth( alphabet ) /
alphabet.length() ) : 0;
double fh = ( fm != null ) ? ( fm.getHeight() / 2.0 ) : 0.0;
return new java.awt.Rectangle( (int) Math.round( ( (double)fw * (double)
x ) / 4.0 ),
(int) Math.round( ( (double)fh * (double)y ) /
4.0 ),
(int) Math.round( ( (double)fw * (double)w ) /
4.0 ),
(int) Math.round( ( (double)fh * (double)h ) /
4.0 ) );
}
public void DUPositionComponent( java.awt.Component comp, int x, int y, int
w, int h, java.awt.Insets formInsets )
{
java.awt.Rectangle rect = DURectangle( x, y, w, h );
if( (comp != this) && (formInsets != null) ) {
rect.x += formInsets.left;
rect.y += formInsets.top;
}
if( (comp == this) && (formInsets != null) && (formInsets.bottom > 0) )
{
rect.height += formInsets.bottom;
}
comp.setBounds( rect );
}
public void setMainForm( boolean isMainForm )
{
__mainForm = isMainForm;
}
public boolean isMainForm()
{
return __mainForm;
}
private boolean createTheForm() throws java.lang.Exception
{
setResizable(true);
java.awt.Container contentPane = getContentPane();
java.awt.Font defaultFont = new java.awt.Font( "Dialog",
java.awt.Font.PLAIN, 12 );
setFont( defaultFont );
boolean retval = true;
addNotify();
try {
jmenubar_1_Test.setText( "Test" );
jmenubar_1_Test.setVerticalAlignment
(javax.swing.SwingConstants.CENTER);
jmenubar_1_Test.setHorizontalAlignment
(javax.swing.SwingConstants.LEFT);
jmenubar_1_Test.setVerticalTextPosition
(javax.swing.SwingConstants.CENTER);
jmenubar_1_Test.setHorizontalTextPosition
(javax.swing.SwingConstants.RIGHT);
jmenubar_1_Test.setFocusPainted( false );
jmenubar_1_Test.setMargin( new java.awt.Insets( 2, 2, 2, 2 ) );
jmenubar_1_Test.setOpaque( true );
}
catch( java.lang.Exception e_jmenubar_1_Test ) {
e_jmenubar_1_Test.printStackTrace();
}
jmenubar_1.add( jmenubar_1_Test );
try {
jmenubar_1_LAFchange.setText( "LAF change" );
jmenubar_1_LAFchange.setVerticalAlignment
(javax.swing.SwingConstants.CENTER);
jmenubar_1_LAFchange.setHorizontalAlignment
(javax.swing.SwingConstants.LEFT);
jmenubar_1_LAFchange.setVerticalTextPosition
(javax.swing.SwingConstants.CENTER);
jmenubar_1_LAFchange.setHorizontalTextPosition
(javax.swing.SwingConstants.RIGHT);
jmenubar_1_LAFchange.setFocusPainted( false );
jmenubar_1_LAFchange.setMargin( new java.awt.Insets( 2, 2, 2, 2 ) );
jmenubar_1_LAFchange.setOpaque( true );
}
catch( java.lang.Exception e_jmenubar_1_LAFchange ) {
e_jmenubar_1_LAFchange.printStackTrace();
}
jmenubar_1_Test.add( jmenubar_1_LAFchange );
setJMenuBar( jmenubar_1 );
java.awt.Insets formInsets = (java.awt.Insets)(contentPane.getInsets
().clone());
contentPane.setBackground( new java.awt.Color( 204, 204, 204 ) );
contentPane.setForeground( new java.awt.Color( 0, 128, 0 ) );
contentPane.setLayout( null );
contentPane.add( (java.awt.Component)jscrollp_1 );
DUPositionComponent( (java.awt.Component) this, 13, 97, 217, 149,
formInsets );
addWindowListener((java.awt.event.WindowListener)this);
try {
jmenubar_1_LAFchange.addActionListener
((java.awt.event.ActionListener)this);
jmenubar_1.setOpaque( true );
jmenubar_1.setFont( new java.awt.Font( "Dialog",
java.awt.Font.BOLD, 12 ) );
jmenubar_1.setBackground( new java.awt.Color( 204, 204, 204 ) );
jmenubar_1.setForeground( java.awt.Color.black );
}
catch( java.lang.Exception e_jmenubar_1 ) {
e_jmenubar_1.printStackTrace();
}
java.awt.Font jscrollp_1_defaultFont = defaultFont;
java.awt.Insets jscrollp_1_insets = null;
try {
DUPositionComponent( (java.awt.Component)jscrollp_1, 16, 10, 171,
96, formInsets );
jscrollp_1.setVerticalScrollBarPolicy
(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
jscrollp_1.setHorizontalScrollBarPolicy
(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jscrollp_1.setFont( jscrollp_1_defaultFont );
jscrollp_1.setBackground( new java.awt.Color( 204, 204, 204 ) );
jscrollp_1.setForeground( java.awt.Color.black );
jscrollp_1.setEnabled(true);
jscrollp_1.setVisible(true);
jscrollp_1_insets = jscrollp_1.getInsets();
}
catch( java.lang.Exception e_jscrollp_1 ) {
e_jscrollp_1.printStackTrace();
}
setResizable(true);
return retval;
}
public boolean create() throws java.lang.Exception
{
boolean retval = true;
retval = retval && createTheForm();
Form1_objectCreated();
setVisible(true);
return retval;
}
public synchronized boolean destroy()
{
if( (java.awt.Container)this instanceof java.awt.Window ) {
((java.awt.Window)(java.awt.Container)this).dispose();
} else {
removeNotify();
}
if( isMainForm() ) {
System.gc();
System.runFinalization();
System.exit(0);
}
return true;
}
private boolean defaultHandleEvent(java.awt.Event event)
{
return false;
}
private void defaultProcessEvent(java.awt.AWTEvent event)
{
super.processEvent(event);
}
public void windowClosed( java.awt.event.WindowEvent event )
{
}
public void windowOpened( java.awt.event.WindowEvent event )
{
}
public void windowClosing( java.awt.event.WindowEvent event )
{
java.lang.Object eventTarget = event.getSource();
if( eventTarget == this ) {
Form1_windowClosing( event );
} else {
unhandledEvent( "java.awt.event.WindowListener", "windowClosing",
event );
}
}
public void windowIconified( java.awt.event.WindowEvent event )
{
}
public void windowActivated( java.awt.event.WindowEvent event )
{
}
public void windowDeiconified( java.awt.event.WindowEvent event )
{
}
public void windowDeactivated( java.awt.event.WindowEvent event )
{
}
public void actionPerformed( java.awt.event.ActionEvent event )
{
java.lang.Object eventTarget = event.getSource();
if( eventTarget == jmenubar_1_LAFchange ) {
jmenubar_1_LAFchange_actionPerformed( event );
} else {
unhandledEvent( "java.awt.event.ActionListener", "actionPerformed",
event );
}
}
public Form1()
{
super();
}
public void processEvent(java.awt.AWTEvent event)
{
defaultProcessEvent(event);
}
private void unhandledEvent( String listenerName, String methodName,
java.lang.Object event )
{
}
private boolean Form1_objectCreated()
{
JTree jtree_1 = new JTree();
DefaultTreeModel tm = (DefaultTreeModel) jtree_1.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tm.getRoot();
root.removeAllChildren();
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("First
Child");
root.add(child1);
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Second
Child");
root.add(child2);
DefaultMutableTreeNode grandchild1 = new DefaultMutableTreeNode("First
Grandchild");
child1.add(grandchild1);
tm.reload();
jscrollp_1.getViewport().setView(jtree_1);
return false;
}
private boolean Form1_windowClosing(java.awt.event.WindowEvent event)
{
setVisible(false);
destroy();
return false;
}
private void jmenubar_1_LAFchange_actionPerformed(
java.awt.event.ActionEvent event )
{
try {
UIManager.setLookAndFeel
( "com.sun.java.swing.plaf.motif.MotifLookAndFeel" );
SwingUtilities.updateComponentTreeUI( this );
} catch ( Exception e ) {}
}
/****************************************
* data members
****************************************/
protected boolean __mainForm = false;
protected javax.swing.JMenuBar jmenubar_1 = new javax.swing.JMenuBar();
protected javax.swing.JMenu jmenubar_1_Test = new javax.swing.JMenu("");
protected javax.swing.JMenuItem jmenubar_1_LAFchange = new
javax.swing.JMenuItem("");
protected javax.swing.JScrollPane jscrollp_1 = new javax.swing.JScrollPane
();
// add your data members here
}
(Review ID: 97649)
======================================================================
11/9/99 eval1127@eng -- reproducible in kestrel-RA (1.3.0 build "I") with the SwingSet demo.
--------------
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
Compile and run the following test program. Select a tree node, then select
the menu opton for LAF change. Note the tree selection is lost when the
components repaint after the UI change.
// add your custom import statements here
import javax.swing.*;
import javax.swing.tree.*;
class Form1 extends javax.swing.JFrame implements
java.awt.event.WindowListener, java.awt.event.ActionListener
{
public static void main(String args[])
{
CreateMainForm();
}
public Form1 CreateMainForm()
{
Form1 form = new Form1();
try {
form.create();
}
catch ( java.lang.Exception __e ) {
__e.printStackTrace();
}
return form;
}
public java.awt.Rectangle DURectangle( int x, int y, int w, int h )
{
String alphabet
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
java.awt.FontMetrics fm = getFontMetrics( getFont() );
double fw = ( fm != null ) ? ( fm.stringWidth( alphabet ) /
alphabet.length() ) : 0;
double fh = ( fm != null ) ? ( fm.getHeight() / 2.0 ) : 0.0;
return new java.awt.Rectangle( (int) Math.round( ( (double)fw * (double)
x ) / 4.0 ),
(int) Math.round( ( (double)fh * (double)y ) /
4.0 ),
(int) Math.round( ( (double)fw * (double)w ) /
4.0 ),
(int) Math.round( ( (double)fh * (double)h ) /
4.0 ) );
}
public void DUPositionComponent( java.awt.Component comp, int x, int y, int
w, int h, java.awt.Insets formInsets )
{
java.awt.Rectangle rect = DURectangle( x, y, w, h );
if( (comp != this) && (formInsets != null) ) {
rect.x += formInsets.left;
rect.y += formInsets.top;
}
if( (comp == this) && (formInsets != null) && (formInsets.bottom > 0) )
{
rect.height += formInsets.bottom;
}
comp.setBounds( rect );
}
public void setMainForm( boolean isMainForm )
{
__mainForm = isMainForm;
}
public boolean isMainForm()
{
return __mainForm;
}
private boolean createTheForm() throws java.lang.Exception
{
setResizable(true);
java.awt.Container contentPane = getContentPane();
java.awt.Font defaultFont = new java.awt.Font( "Dialog",
java.awt.Font.PLAIN, 12 );
setFont( defaultFont );
boolean retval = true;
addNotify();
try {
jmenubar_1_Test.setText( "Test" );
jmenubar_1_Test.setVerticalAlignment
(javax.swing.SwingConstants.CENTER);
jmenubar_1_Test.setHorizontalAlignment
(javax.swing.SwingConstants.LEFT);
jmenubar_1_Test.setVerticalTextPosition
(javax.swing.SwingConstants.CENTER);
jmenubar_1_Test.setHorizontalTextPosition
(javax.swing.SwingConstants.RIGHT);
jmenubar_1_Test.setFocusPainted( false );
jmenubar_1_Test.setMargin( new java.awt.Insets( 2, 2, 2, 2 ) );
jmenubar_1_Test.setOpaque( true );
}
catch( java.lang.Exception e_jmenubar_1_Test ) {
e_jmenubar_1_Test.printStackTrace();
}
jmenubar_1.add( jmenubar_1_Test );
try {
jmenubar_1_LAFchange.setText( "LAF change" );
jmenubar_1_LAFchange.setVerticalAlignment
(javax.swing.SwingConstants.CENTER);
jmenubar_1_LAFchange.setHorizontalAlignment
(javax.swing.SwingConstants.LEFT);
jmenubar_1_LAFchange.setVerticalTextPosition
(javax.swing.SwingConstants.CENTER);
jmenubar_1_LAFchange.setHorizontalTextPosition
(javax.swing.SwingConstants.RIGHT);
jmenubar_1_LAFchange.setFocusPainted( false );
jmenubar_1_LAFchange.setMargin( new java.awt.Insets( 2, 2, 2, 2 ) );
jmenubar_1_LAFchange.setOpaque( true );
}
catch( java.lang.Exception e_jmenubar_1_LAFchange ) {
e_jmenubar_1_LAFchange.printStackTrace();
}
jmenubar_1_Test.add( jmenubar_1_LAFchange );
setJMenuBar( jmenubar_1 );
java.awt.Insets formInsets = (java.awt.Insets)(contentPane.getInsets
().clone());
contentPane.setBackground( new java.awt.Color( 204, 204, 204 ) );
contentPane.setForeground( new java.awt.Color( 0, 128, 0 ) );
contentPane.setLayout( null );
contentPane.add( (java.awt.Component)jscrollp_1 );
DUPositionComponent( (java.awt.Component) this, 13, 97, 217, 149,
formInsets );
addWindowListener((java.awt.event.WindowListener)this);
try {
jmenubar_1_LAFchange.addActionListener
((java.awt.event.ActionListener)this);
jmenubar_1.setOpaque( true );
jmenubar_1.setFont( new java.awt.Font( "Dialog",
java.awt.Font.BOLD, 12 ) );
jmenubar_1.setBackground( new java.awt.Color( 204, 204, 204 ) );
jmenubar_1.setForeground( java.awt.Color.black );
}
catch( java.lang.Exception e_jmenubar_1 ) {
e_jmenubar_1.printStackTrace();
}
java.awt.Font jscrollp_1_defaultFont = defaultFont;
java.awt.Insets jscrollp_1_insets = null;
try {
DUPositionComponent( (java.awt.Component)jscrollp_1, 16, 10, 171,
96, formInsets );
jscrollp_1.setVerticalScrollBarPolicy
(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
jscrollp_1.setHorizontalScrollBarPolicy
(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jscrollp_1.setFont( jscrollp_1_defaultFont );
jscrollp_1.setBackground( new java.awt.Color( 204, 204, 204 ) );
jscrollp_1.setForeground( java.awt.Color.black );
jscrollp_1.setEnabled(true);
jscrollp_1.setVisible(true);
jscrollp_1_insets = jscrollp_1.getInsets();
}
catch( java.lang.Exception e_jscrollp_1 ) {
e_jscrollp_1.printStackTrace();
}
setResizable(true);
return retval;
}
public boolean create() throws java.lang.Exception
{
boolean retval = true;
retval = retval && createTheForm();
Form1_objectCreated();
setVisible(true);
return retval;
}
public synchronized boolean destroy()
{
if( (java.awt.Container)this instanceof java.awt.Window ) {
((java.awt.Window)(java.awt.Container)this).dispose();
} else {
removeNotify();
}
if( isMainForm() ) {
System.gc();
System.runFinalization();
System.exit(0);
}
return true;
}
private boolean defaultHandleEvent(java.awt.Event event)
{
return false;
}
private void defaultProcessEvent(java.awt.AWTEvent event)
{
super.processEvent(event);
}
public void windowClosed( java.awt.event.WindowEvent event )
{
}
public void windowOpened( java.awt.event.WindowEvent event )
{
}
public void windowClosing( java.awt.event.WindowEvent event )
{
java.lang.Object eventTarget = event.getSource();
if( eventTarget == this ) {
Form1_windowClosing( event );
} else {
unhandledEvent( "java.awt.event.WindowListener", "windowClosing",
event );
}
}
public void windowIconified( java.awt.event.WindowEvent event )
{
}
public void windowActivated( java.awt.event.WindowEvent event )
{
}
public void windowDeiconified( java.awt.event.WindowEvent event )
{
}
public void windowDeactivated( java.awt.event.WindowEvent event )
{
}
public void actionPerformed( java.awt.event.ActionEvent event )
{
java.lang.Object eventTarget = event.getSource();
if( eventTarget == jmenubar_1_LAFchange ) {
jmenubar_1_LAFchange_actionPerformed( event );
} else {
unhandledEvent( "java.awt.event.ActionListener", "actionPerformed",
event );
}
}
public Form1()
{
super();
}
public void processEvent(java.awt.AWTEvent event)
{
defaultProcessEvent(event);
}
private void unhandledEvent( String listenerName, String methodName,
java.lang.Object event )
{
}
private boolean Form1_objectCreated()
{
JTree jtree_1 = new JTree();
DefaultTreeModel tm = (DefaultTreeModel) jtree_1.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tm.getRoot();
root.removeAllChildren();
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("First
Child");
root.add(child1);
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Second
Child");
root.add(child2);
DefaultMutableTreeNode grandchild1 = new DefaultMutableTreeNode("First
Grandchild");
child1.add(grandchild1);
tm.reload();
jscrollp_1.getViewport().setView(jtree_1);
return false;
}
private boolean Form1_windowClosing(java.awt.event.WindowEvent event)
{
setVisible(false);
destroy();
return false;
}
private void jmenubar_1_LAFchange_actionPerformed(
java.awt.event.ActionEvent event )
{
try {
UIManager.setLookAndFeel
( "com.sun.java.swing.plaf.motif.MotifLookAndFeel" );
SwingUtilities.updateComponentTreeUI( this );
} catch ( Exception e ) {}
}
/****************************************
* data members
****************************************/
protected boolean __mainForm = false;
protected javax.swing.JMenuBar jmenubar_1 = new javax.swing.JMenuBar();
protected javax.swing.JMenu jmenubar_1_Test = new javax.swing.JMenu("");
protected javax.swing.JMenuItem jmenubar_1_LAFchange = new
javax.swing.JMenuItem("");
protected javax.swing.JScrollPane jscrollp_1 = new javax.swing.JScrollPane
();
// add your data members here
}
(Review ID: 97649)
======================================================================
- duplicates
-
JDK-4246830 Switching UI should not reset Selections in JTree
- Closed