-
Bug
-
Resolution: Fixed
-
P3
-
1.3.0
-
beta2
-
x86
-
windows_95
Name: boT120536 Date: 12/14/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
1. Compile The following source and run it. Press Ctrl+F6 and Ctrl+Shift+F6 several times. Then change Look&Feel from menu. Then press Ctrl+F6 again. In some cases it simply doesn't work here, in some cases it's result became unpredictable (it may work like "previous" key or may select windows in arbitrary order or select previous active window). Note, that my own ActionListener for Ctrl-F6 key (menu Window>Next) doesn't work at all (no "Next" output in stdout). Select "Next" from "Window" menu - it works correctly. If You will replace F6 in the source by F11 (e.g.), it will work without any errors.
2. Source code
// START OF SOURCE
package Painter;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class PainterUI extends JFrame{
private JDesktopPane dp=null;
private Vector vImageNames=null;
private JCheckBoxMenuItem[] cbLookAndFeel=null;
private UIManager.LookAndFeelInfo[] lafi=null;
private JMenu mWindow=null;
private JMenuItem miPrevious=null;
private JMenuItem miNext=null;
// constructor
public PainterUI(){
super("Painter v0.1");
setSize(new Dimension(440,480));
setLocation(0,0);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
JPanel newContentPane=new JPanel();
newContentPane.setLayout(new BorderLayout());
dp=new JDesktopPane();
newContentPane.add(dp,BorderLayout.CENTER);
this.setContentPane(newContentPane);
vImageNames=new Vector();
JInternalFrame ifr=null;
for ( int i=0; i<5 ; i++ )
{
ifr=new JInternalFrame("Untitled-"+(i+1),true,true,true,true);
ifr.setSize(new Dimension(200,200));
ifr.setLocation(i*50,i*50);
vImageNames.addElement("Untitled-"+(i+1));
dp.add(ifr);
ifr.show();
}
JMenuBar mb=new JMenuBar();
lafi=UIManager.getInstalledLookAndFeels();
cbLookAndFeel=new JCheckBoxMenuItem[lafi.length];
JMenu mLookAndFeel=new JMenu("L&F");
mLookAndFeel.setMnemonic(KeyEvent.VK_L);
for ( int i=0; i<cbLookAndFeel.length; i++)
{
cbLookAndFeel[i]=new JCheckBoxMenuItem(lafi[i].getName(), false);
cbLookAndFeel[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int index=0;
while ( !cbLookAndFeel[index].equals(e.getSource()) ) index++;
try{
UIManager.setLookAndFeel(lafi[index].getClassName());
SwingUtilities.updateComponentTreeUI(PainterUI.this);
}catch(Exception ex){
cbLookAndFeel[index].setState(false);
JOptionPane.showMessageDialog(PainterUI.this, "Can't set new Look&Feel", "Error",
JOptionPane.ERROR_MESSAGE);
}
for ( int j=0; j<cbLookAndFeel.length; j++)
{
if ( !cbLookAndFeel[j].equals(e.getSource()) ) {
cbLookAndFeel[j].setState(false);
}
}
}
});
mLookAndFeel.add(cbLookAndFeel[i]);
}
String plafName=UIManager.getLookAndFeel().getName();
int index=0;
while ( !cbLookAndFeel[index].getText().equals(plafName) ) index++;
cbLookAndFeel[index].setState(true);
mb.add(mLookAndFeel);
// creating "Window" menu
mWindow=new JMenu("Window");
mWindow.setMnemonic(KeyEvent.VK_W);
miPrevious=new JMenuItem("Previous");
miPrevious.setMnemonic(KeyEvent.VK_P);
miPrevious.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6,
InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK));
miPrevious.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JInternalFrame f=dp.getSelectedFrame();
if ( f==null ){
return;
}
String imageName=f.getTitle();
int i=0;
while ( !vImageNames.elementAt(i).equals(imageName) ){
i++;
if ( i==vImageNames.size() ){
System.out.println(imageName+" not found");
return;
}
}
int pIndex = (i==0) ? vImageNames.size()-1 : i-1;
String prevImageName=(String)vImageNames.elementAt(pIndex);
JInternalFrame[] allFrames=dp.getAllFrames();
for ( int j=0; j<allFrames.length; j++)
{
if ( allFrames[j].getTitle().equals(prevImageName) ){
try{
allFrames[j].setSelected(true);
}catch(Exception ex){
System.out.println("Can't select "+prevImageName);
return;
}
break;
}
}
System.out.println("Previous");
}
});
miNext=new JMenuItem("Next");
miNext.setMnemonic(KeyEvent.VK_N);
miNext.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6,
InputEvent.CTRL_MASK));
miNext.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JInternalFrame f=dp.getSelectedFrame();
if ( f==null ){
return;
}
String imageName=f.getTitle();
int i=0;
while ( !vImageNames.elementAt(i).equals(imageName) ){
i++;
if ( i==vImageNames.size() ){
System.out.println(imageName+" not found");
return;
}
}
int nIndex = (i==(vImageNames.size()-1)) ? 0 : i+1;
String nextImageName=(String)vImageNames.elementAt(nIndex);
JInternalFrame[] allFrames=dp.getAllFrames();
for ( int j=0; j<allFrames.length; j++)
{
if ( allFrames[j].getTitle().equals(nextImageName) ){
try{
allFrames[j].setSelected(true);
}catch(Exception ex){
System.out.println("Can't select "+nextImageName);
return;
}
break;
}
}
System.out.println("Next");
}
});
mWindow.add(miNext);
mWindow.add(miPrevious);
mb.add(mWindow);
setJMenuBar(mb);
show();
try{
ifr.setSelected(true);
}catch(java.beans.PropertyVetoException ex){
}
}//end of constructor
public static void main( String args[] )
{
PainterUI p=new PainterUI();
}
}
// END OF SOURCE
3. no error messages
4. no trace information available
5. None
(Review ID: 107853)
======================================================================