The following issue im having is very small but extremely annoying and i cant figure why it wont work. I Create a frame within another frame and would like the smaller second frame to grab the focus (be selected) as soon as it is created. I use the method setSelected() in another one of my classes and it works perfectly, but here it does not…If anyone might be able to tell me what might be the problem, that would be great…
The code for my class is as follows: The problem is that openigFrame does not appear selected when created, it must be clicked upon to get the focus….
public class MainProgramFrame extends JFrame { private JDesktopPane desktop; private JInternalFrame openingFrame; private JRadioButton newButton; private JRadioButton openButton; int i = 1;
public static void main(String arg[]){ MainProgramFrame mpf = new MainProgramFrame(); mpf.show(); }
public MainProgramFrame() { super("GATACA"); this.setSize(900,650); this.setLocation(50,30); this.setBackground(Color.gray);
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { }
init(); }
public void init() { desktop = new JDesktopPane(); desktop.setBackground(Color.gray); setContentPane(desktop); createGUI(); }
public void createGUI() //throws PropertyVetoException { AppMenuBar AppMenuBar = new AppMenuBar(); setJMenuBar((JMenuBar)AppMenuBar);
openingFrame = new JInternalFrame("Welcome to GATACA", true, true, true, true);
JPanel newPanel = new JPanel(); newButton = new JRadioButton("Create a new experiment:");
JPanel openPanel = new JPanel(); openButton = new JRadioButton("Open existing experiment:");
ButtonGroup gp = new ButtonGroup(); gp.add(newButton); gp.add(openButton);
newPanel.add(newButton); openPanel.add(openButton);
openingFrame.getContentPane().setLayout(new GridLayout(3,1)); openingFrame.getContentPane().add(newPanel); openingFrame.getContentPane().add(openPanel); desktop.add(openingFrame);
openingFrame.setSize(500,150); openingFrame.setLocation(200,50); openingFrame.setBackground(Color.lightGray); openingFrame.setVisible(true); openButton.setSelected(true);
try{ openingFrame.setSelected(true); }catch (PropertyVetoException e) {}
JPanel buttonPanel = new JPanel(); JButton okButton = new JButton("Ok"); buttonPanel.add(okButton);
okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (openButton.isSelected()) { createExperiment(); //openingFrame.hide(); openingFrame.setVisible(false); repaint(); } else if (newButton.isSelected()) {
}
} } );
JButton cancelButton = new JButton("Cancel"); cancelButton.setSize(1,1); buttonPanel.add(cancelButton);
JSeparator sep = new JSeparator(); buttonPanel.add(sep);
openingFrame.getContentPane().add(buttonPanel);
}
public class AppMenuBar extends JMenuBar { Vector menus = new Vector(); public AppMenuBar(){ createMenus();}
public void createMenus(){ createFileMenu(); } public JMenu createFileMenu() { JMenu fileMenu = new JMenu("Experiment"); JMenuItem open = new JMenuItem("Open..."); open.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ createExperiment();
} } );
fileMenu.add(open); add(fileMenu); return fileMenu; } }
public void createExperiment() { ImageManip2D4Two im = new ImageManip2D4Two(); im.setSize(780,400); im.initializeIM(i);
desktop.add(im); im.moveToFront(); im.setVisible(true); try{ im.setSelected(true); }catch (PropertyVetoException e) {}
i++; }
}
***************************************************************************** David Braun-Friedman Programador de Telecomunicaciones Departamento de Electrónica y Comunicaciones Email (CEIT): [EMAIL PROTECTED] Email (Fuera): [EMAIL PROTECTED] Tlfno: 943 212 800 Extensión: 289 Móvil: 628527739
Paseo Manuel de
Lardizabal, 15
*****************************************************************************
|
<<image001.jpg>>