Focus auf einen JInternalFrame

Flex IV

Mitglied
Hallo,
bin mal wieder am verzweifeln, ich schaffe es nicht dem JInternalFrame den Focus zu verschaffen, habs mit jInternalFrame.requestFocus(); versucht, das geht aber nicht:

Java:
package tests;

import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
import javax.swing.JDesktopPane;
import java.awt.GridBagLayout;
import javax.swing.JInternalFrame;
import java.awt.Rectangle;
import javax.swing.JTextField;

public class TestFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JSplitPane jSplitPane = null;
	private JDesktopPane jDesktopPane = null;
	private JPanel jPanel = null;
	private JInternalFrame jInternalFrame = null;
	private JPanel jContentPane1 = null;
	private JTextField jTextField = null;

	/**
	 * This method initializes jSplitPane	
	 * 	
	 * @return javax.swing.JSplitPane	
	 */
	private JSplitPane getJSplitPane() {
		if (jSplitPane == null) {
			jSplitPane = new JSplitPane();
			jSplitPane.setLeftComponent(getJDesktopPane());
			jSplitPane.setRightComponent(getJPanel());
			jSplitPane.setDividerLocation(142);
		}
		return jSplitPane;
	}

	/**
	 * This method initializes jDesktopPane	
	 * 	
	 * @return javax.swing.JDesktopPane	
	 */
	private JDesktopPane getJDesktopPane() {
		if (jDesktopPane == null) {
			jDesktopPane = new JDesktopPane();
			jDesktopPane.add(getJInternalFrame(), null);
		}
		return jDesktopPane;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(new GridBagLayout());
		}
		return jPanel;
	}

	/**
	 * This method initializes jInternalFrame	
	 * 	
	 * @return javax.swing.JInternalFrame	
	 */
	private JInternalFrame getJInternalFrame() {
		if (jInternalFrame == null) {
			jInternalFrame = new JInternalFrame();
			jInternalFrame.setBounds(new Rectangle(0, 00, 140, 143));
			jInternalFrame.setContentPane(getJContentPane1());
			jInternalFrame.setClosable(true);
			jInternalFrame.setResizable(true);
			jInternalFrame.setIconifiable(true);
			jInternalFrame.setTitle("Auswahl:");

			jInternalFrame.show();
			
			jInternalFrame.requestFocus();
			
		}
		return jInternalFrame;
	}

	/**
	 * This method initializes jContentPane1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPane1() {
		if (jContentPane1 == null) {
			jContentPane1 = new JPanel();
			jContentPane1.setLayout(new BorderLayout());
			jContentPane1.add(getJTextField(), BorderLayout.NORTH);
		}
		return jContentPane1;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
		}
		return jTextField;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				TestFrame thisClass = new TestFrame();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}

	/**
	 * This is the default constructor
	 */
	public TestFrame() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJSplitPane(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

}

Wisst Ihr wie es geht (das Internal Frame soll also automatisch den Zustand haben, als hätte man einmal kurz hingeklickt)

Danke
 
Zuletzt bearbeitet von einem Moderator:
Zurück