Use of JInternalFrame in populated JFrame?

Hi,
For my application I'm working on a simple Help screen (I do not want to use JavaHelp). The help screen I have developed is based on a JInternalFrame. This help screen is to be filled with HTML formatted text, that I load at start up. The loading of the text file works fine.
The application displays everything in a JFrame. When request the helpscreen is also to be displayed.
At start up I only display a JPanel taking up only (the middle) part of the JFrame. When I request the help screen, it is displayed to the right of the JPanel.
When I request the help screen when my JFrame has content, it is not shown. Would you know why that is? Does the help screen have to compete for screen space, and failing in it? Should I use something of an Z-order to get my Help screen to be displayed over the other content of the JFrame?
Abel
The following (non compilable code, it contains errors :-( ) might show what I'm trying to do:
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import javax.swing.*;
public class HelpScreenPlace extends JFrame implements ActionListener {
     static HelpScreenPlace helpScreenPlace;
     static JMenuBar menuBar;
     static JMenu menu;
     static JMenuItem hMenuItem;
     static JInternalFrame helpFrame;
     static JEditorPane editorScrollPane;
     static int WIDTH = 450;
     static int HEIGHT = 350;
     static JTextField userNameField;
     static JLabel unameLabel = new JLabel("Username: ", SwingConstants.RIGHT);
     static JTextField passwordField;
     static JLabel passLabel = new JLabel("Password: ", SwingConstants.RIGHT);
     public HelpScreenPlace () {
          super("HelpScreenPlace");
          menuBar = new JMenuBar();
          menu = new JMenu ("Help");
          menu.setMnemonic(KeyEvent.VK_H);
          menu.getAccessibleContext().setAccessibleDescription("Help menu");
          menuBar.add(menu);          
          // The help contents functionality
          // TODO help functionality
          hMenuItem = new JMenuItem ("Help Contents");
          hMenuItem.setMnemonic(KeyEvent.VK_H);
          // What to do to get the keyboard shortcut F1 (no ALTMASK and the like)?
          hMenuItem.addActionListener(this);
          menu.add(hMenuItem);
          add(menuBar);
     public static void createAndShowGUI() {
          helpScreenPlace = new HelpScreenPlace();
          // Add a login panel (without functionality
          JPanel logInPanel = new JPanel();
          logInPanel.setLayout(new GridLayout (3, 2)); // 3 rows, 2 columns
          logInPanel.setBounds (WIDTH, HEIGHT, WIDTH, HEIGHT);
          userNameField = new JTextField ("jdoe", 10);
          passwordField = new JPasswordField("unanimous_unite", 10);
          logInPanel.add (unameLabel);
          logInPanel.add (userNameField);
          logInPanel.add(passLabel);
          logInPanel.add(passwordField);
          JComponent okButton = createButtonPanel();
          logInPanel.add(okButton);
          // An empty panel to fill up the empty spot after the button
          JPanel emptyPanel = new JPanel();
          emptyPanel.setBackground(Color.WHITE);
          logInPanel.add(emptyPanel);
          logInPanel.setSize(WIDTH, HEIGHT);
          logInPanel.setVisible (true);
     static JComponent createButtonPanel() {
          JPanel panel = new JPanel(new GridLayout(0,1));
          JButton okButton = new JButton("OK");
          okButton.setActionCommand("OK");
          // okButton.addActionListener(this); // Cannot use this in static reference (1st error)
          panel.add(okButton);
          return panel;
     public void actionPerformed (ActionEvent event) {
          String message = event.getActionCommand();
          if (message.equals("Help Contents")) {
               helpFrame = new HelpFrame(); //  cannot convert from HelpScreenPlace.HelpFrame to JInternalFrame (2nd error)
               helpFrame.setVisible(true);
               add(helpFrame);
     public static void main(String[] args) {
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
               public void run() {
                    createAndShowGUI();
     private class CloseListener extends WindowAdapter {
          public void windowClosing (WindowEvent we) {
               System.exit(0);
        // - Syntax error on token "class", invalid Type
     // - Syntax error on token "extends", throws expected (etc on errors)
     private static class HelpFrame() extends JInternalFrame {
          super ("Help",
                    true,          // HelpFrame is resizable
                    true,          // HelpFrame is closable
                    true,          // HelpFrame is maximixable
                    true);          // HelpFrame is iconifiable
          // Get the helpPane from the model
          helpPane = model.getHelpPane();
          helpPane.setBackground(Color.WHITE);
          // Add helpPane to JScrollPane
          JEditorPane editorPane = getHelpPane();
          JScrollPane editorScrollPane = new JScrollPane(editorPane);
          editorScrollPane.setVerticalScrollBarPolicy(
                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
          editorScrollPane.setSize(250, 500);
          // editorScrollPane.setPreferredSize(new Dimension(250, 500));
          editorScrollPane.setMinimumSize(new Dimension(10, 10));
          add(editorScrollPane);
     JEditorPane getHelpPane() {
          JEditorPane pane = new JEditorPane();
          pane.setEditable(false); // Not editable
          java.net.URL helpURL = HelpFrame.class.getResource("HelpWindow.html");
          if (helpURL != null) {
               try {
                    System.out.println ("Getting help file " + helpURL);
                    pane.setPage(helpURL);
               } catch (IOException e) {
                    System.out.println ("Attempted to read a bad URL: " + helpURL);
          } else {
               System.out.println ("Couldn't find file: HelpWindow.html");
          return pane;
}For what it's worth, this is the HelpWindow.html file:
<html>
<body>
This is the help file for this project.<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
</body>
</html>

JInternalFrame's are meant to live in JDesktopPanes. Of course, they dont' strickly have to, but you aren't going to get it to act properly like an internal frame without jumping thru a lot of hoops. At least try packing or setting the size of the internal frame when you add it. If your layout is a border layout, then you're probably replacing the contents of the frame. And anyway, I don't see in your code where you are actually adding the main UI to the frame in the first place.
Of course, you can wrap your whole UI in a JDesktopPane so that the main display is a panel filling the whole desktop pane on a layer, then add the help frame in there on a higher layer.
Or maybe just not worry about internal frames and use a JDialog or another JFrame instead.
Edited by: bsampieri on Apr 15, 2008 10:57 AM

Similar Messages

  • Use JWindow, JInternalFrame, JPanel, or JDialog

    Hello,
    My main window application extends a JFrame. When a component of the JFrame is mouse clicked,I want to open a popup window on top of this frame.
    The opened window is used to receive input from the user; with these properties: title bar, resizeable, can close with the "X" on the right side of the title bar, no minimizable or maximizable buttons on the title bar.
    1. I am very unsure whether I should use: a JWindow, JInternalFrame, JPanel, JDialog, JPopupMenu (probably not since I don't need a menu) to create the popup window. I think I should use JWindow, but am not sure.
    2. Also, I am unsure whether I can use JWindow and JInternalFrame with JFrame as the main app window.
    Thank you for your advice.

    If you want a popup window on top of this frame, you can either choose JFrame, JDialog or JWindow. They all have the own characteristics.
    JFrame: Usually application will use it as the base. Because It has a title bar with minimizable, maximizable and exit button.
    JDialog: Usually work as a option / peference / about dialog (Ex. Just click the IE about to see). Because it has a smaller title bar with only maximizable and exit button and the model setting. If model is to TRUE, that means all the other area of the window will be disable except the opened dialog own.
    JWindow: Usually use as a splash to display logo or welcome message.
    JInternalFrame: It display inside a desktop panel of JFrame. Just like the multi-documents function inside the MS Words.

  • Error in using  the title of the JFrame window as handle

    Hello,
    To get the handle of JFrame, i used FindWindow. I used as given below in JNI.
    JNIEXPORT void JNICALL
    Java_T_Tmanager_init1(JNIEnv *env, jclass cla,jstring str)
    const char* cw = env->GetStringUTFChars(str, 0);
         HWND hwnd = FindWindow(NULL,cw);
         env->ReleaseStringUTFChars(str, cw);
         InitTwain(hwnd);
    When i tried to create dll file, it is showing the following error :
    TmanagerImpl1.obj : error LNK2001 : unresolved external symbol impFindWindowA@8
    sample.dll: fatal error LNK1120 : 1 unresolved externals
    How to solve this problem? Help me in solving this.
    Thanks,
    Sri

    plz help me !!!!!

  • How to fix the position of JInternalFrames added in JFrame.

    Hay Frnds, I am having a problem. I have a JFrame ,in which i have added five JInternalFrames. My problem is that i want to fix the position of thaose Internal frames so that user cant move them from one place to other. Is there any way to fix there position. Plz reply as soon as possible. Its very urgent.
    Thanks.

    import javax.swing.plaf.basic.*;
            BasicInternalFrameUI internalframeUI = (BasicInternalFrameUI)frame1.getUI();
            internalframeUI.getNorthPane().addMouseListener(new MouseAdapter() {
                public void mouseReleased(MouseEvent evt) {
                    frame1.setBounds(0, 0, frame1.getWidth(), frame1.getHeight());
            });

  • Please help! Image only shows when i use Applets instead of Frame/JFrame

    The following classes don't work because the Canvas shows just background colour. However, when I let my class "MyContainer" extend Applet instead(and running the Applet instead of the StartUp class that creates a JFrame) of Frame/JFrame i get my Image on the Canvas showing, WHY?
    code:
    public class StartUp {
    public static void main(String[] arg) {
    MyContainer my = new MyContainer();
         my.setSize(500, 400);
         my.setVisible(true);
    public class MyContainer extends JFrame {
    MyCanvas m;
    public void MyContainer() {
         m=new MyCanvas();
         this.setSize(320, 320);
    this.setLayout(new GridLayout(1, 1, 0, 0));
    this.add(m);
    this.setVisible(true);
    public class MyCanvas extends Canvas {
    Image im;
    public MyCanvas() {
    im=Toolkit.getDefaultToolkit().createImage("c:\\miniferrari.jpg");
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public void paint(Graphics g) {
    g.drawImage(im, 0, 0, this);
    private void jbInit() throws Exception {
    this.setBackground(Color.darkGray);

    as you are using a JFrame, you should refer to it's contentpane:
    this.getContentPane().setLayout(new GridLayout(1, 1, 0, 0));
    this.getContentPane().add(m);

  • Cursor problem when using inside JInternalFrame

    HI there,
    My problem is describe below:
    JDK Environment: 1.3
    Scenario: A JLabel with a mouseListener inside a JInternalFrame. The mouseListener listen to the mouseEntered and mouseExited event. When it is mouseEntered event,it change to Cursor.HAND_CURSOR , when it is mouseExited event,it change to Cursor.DEFAULT_CURSOR. This works fine inside JInternalFrame. I had tested that...
    The problem occurs when the mouse move OUTSIDE of the JInternalFrame. The cursor won't convert anymore after the mouse move outside the Jinternalframe, is it a swing bug? any suggestion there?
    Thank you.
    Application Developer,
    Chin
    ---------code attached for clarification -----------------
    label.addMouseListener(new MouseAdapter(){
    public void mouseEntered(MouseEvent me){
    frame.getContentPane().setCursor (Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    public void mouseExited(MouseEvent me){
    frame.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    WHERE label sit inside a JInternalFrame...

    I believe you are setting the cursor to far back in the containment hiearchy. Each JComponent could have a separate Cursor. I cannot recall how to make a JInternalFrame active so you'll have to click it to see the Cursors on the Iframeimport java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CursorTest extends JFrame
       private JDesktopPane desk;
       private JInternalFrame f;
       private JLabel l;
       public CursorTest()
          super("Cursor Test");
          setSize(500, 400);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          l = new JLabel("Point Mouse Here");
          l.setCursor (Cursor.getPredefinedCursor
             (Cursor.HAND_CURSOR));
          f = new JInternalFrame("Cursor Zone",
                      true, true, true, true);
          f.getContentPane().setLayout(new FlowLayout());
          ((JComponent)f.getContentPane()).setCursor
                (Cursor.getPredefinedCursor
                (Cursor.CROSSHAIR_CURSOR));
          f.getContentPane().add(l);
          f.setVisible(true);
          desk = new JDesktopPane();
          desk.setCursor(Cursor.getPredefinedCursor
                   (Cursor.MOVE_CURSOR));
          desk.add(f);
          f.setBounds(50, 50, 144, 89);
          setLayeredPane(desk);
       public static void main(String[] args)
          CursorTest cT = new CursorTest();
          cT.setVisible(true);
          cT.desk.getDesktopManager().
             activateFrame(cT.f);
    }

  • Opening a webpage using url.getConnection and populating?

    Hi
    I want to write a tool that opens a webpage given the URL and populates the page with provided information and clicks the button i.e. want a tool that automates this workflow.
    I understand I can tweak with url.getConnection and get the page populated but I am clueless about populating the page automatically with the data. Is there any way to do it?
    Thanks
    Raja

    Hi
    Thanks for your immediate knowledge sharing, ya right JSP can be accessed as it resides in the server also I understand the HTML coding is more than enough for me to understand the values I need to pass to given the input type of fields with the FORM tag.
    Having understood thus far, you people mention getting the HTML code but how do I get that programatically, it is that I can load the JSP/page using URL.getConnection and open the page in the browser, one way is doing VIEW SOURCE manually and getting the code, can you educate me on how to do it programatically to view source of the displaying page on a browser?
    Thanks
    Raja

  • ADF mobile Client App: Issue about using db sequence for populating row_id

    Hi,
    I'm working on an ADF mobile client app POC project. In the mobile app, new record can be created, the column type for row_id is VARCHAR2(15), I used the db sequence created in MC db, converted the seq number to a string, then set row_id via initDefaults method.
    The new records are created and row_ids are set with the proper sequence numbers when first time launching the client app in blackberry simulator. But if I exit the app and re-launch the app again, I got net.rim.device.api.database.DataTypeExpection when trying to create a new record.
    Could anyone please help me and let me know what could cause this issue? What should be the proper way to populate the row_id? Appreciate your response in advance!
    Jdev/ADFMobile extension version:
    11.1.1.4.0 build 5860
    mobile server version:
    10.3.0.3
    blackberry version:
    BlackBerry JDE 5.0.0
    BlackBerry Smartphone Simulators 6.0.0.141 (9800)
    Code:
    public class SOrgExtEOImpl extends EntityImpl {
    protected void initDefaults() {
    super.initDefaults();
    SequenceImpl seq = new SequenceImpl("S_SIEBELMOBILE_S_ORG_EXT", getDBTransaction());
    populateAttributeAsChanged(ROWID1, seq.getSequenceNumber().toString());
    Log:
    First time launching the MC app:
    [FINE - adfnmc.bindings - BC4JIteratorBinding - createRow]
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 0 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 1 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 2 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 3 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 4 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 5 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 6 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 7 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 8 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 9 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 10 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 11 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 12 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 1 to 2010-12-20 14:58:13.0
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 3 to 2010-12-20 14:58:13.0
    [FINE - adfnmc.model - SequenceImpl - create] Database SQLite doesn't support sequences natively; creating TableSequenceImpl for
    S_SIEBELMOBILE_S_ORG_EXT
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 0 to 73501
    [FINE - adfnmc.model - EntityImpl - getAttribute] Retrieved from siebel.mobile.SOrgExtEO.CreatedBy at index 2
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 2 to 1-11ZQ
    [FINE - adfnmc.model - EntityImpl - getAttribute] Retrieved from siebel.mobile.SOrgExtEO.LastUpdBy at index 4
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 4 to 1-53Y
    [FINE - adfnmc.model - EntityImpl - getAttribute] Retrieved from siebel.mobile.SOrgExtEO.BuId at index 5
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 5 to 1-1DG
    [INFO - adfnmc.model - MetaObjectManager - findOrLoadMetaObject] MetaObject siebel.mobile.AccountAddressFKAssoc not found in cache, so
    loading it from XML
    [INFO - adfnmc.model - MetaObjectManager - findOrLoadMetaObject] MetaObject siebel.mobile.ActivityAccountFKAssoc not found in cache, so
    loading it from XML
    [FINE - adfnmc.bindings - BC4JIteratorBinding - notifyRowInserted]
    [FINE - adfnmc.bindings - IteratorExecutableBindingImpl - rowInserted] IterBinding - AccountPageDef:AccountAddressView1Iterator
    [FINE - adfnmc.bindings - IteratorExecutableBindingImpl - notifyRowInserted] IterBinding - AccountPageDef:AccountAddressView1Iterator
    [FINE - adfnmc.bindings - RangeBindingImpl - rowInserted] AccountAddressView1
    [FINE - adfnmc.bindings - RangeBindingImpl - notifyNewElement] AccountAddressView1, index:0
    [FINE - adfnmc.ui - BBTable - newElement] relativeIndex = 0
    [FINE - adfnmc.bindings - RangeBindingImpl - setVariableIndex] Begin, AccountAddressView1, listener: oracle.adfnmc.component.ui.BBTable$1
    [FINE - adfnmc.bindings - SimpleContext$Variables - setVariable] Setting variable "row" to expression #
    {AccountPageDef_AccountAddressView1_rowAlias}
    [FINE - adfnmc.ui - BBOutputText - endInit]
    Re-launching the MC app:
    INFO - adfnmc.bindings - BC4JOperationBinding - execute] Preparing to execute OperationBinding id:'CreateInsert'
    [FINE - adfnmc.bindings - BC4JIteratorBinding - createRow]
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 0 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 1 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 2 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 3 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 4 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 5 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 6 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 7 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 8 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 9 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 10 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 11 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 12 to
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 1 to 2010-12-20 15:08:35.0
    [FINEST - adfnmc.model - EntityImpl - populateAttribute] Setting value at index 3 to 2010-12-20 15:08:35.0
    [FINE - adfnmc.model - SequenceImpl - create] Database SQLite doesn't support sequences natively; creating TableSequenceImpl for
    S_SIEBELMOBILE_S_ORG_EXT
    [INFO - adfnmc.ui - ErrorHandlerImpl - reportException] BindingContainer: AccountPageDef, exception: oracle.adfnmc.AMCJboException
    [WARNING - adfnmc.ui - ErrorHandlerImpl - reportException] [oracle.jbo.server.SequenceImpl$TableSequenceImpl.retrieveSequenceParamsFromDB]
    oracle.adfnmc.AMCJboException: ADF-MNC-60109: Error retrieving sequence parameters for sequence S_SIEBELMOBILE_S_ORG_EXT
    [WARNING - adfnmc.ui - ErrorHandlerImpl - reportException] oracle.adfnmc.java.sql.SQLException:
    net.rim.device.api.database.DataTypeException:Datatype mismatch
    [WARNING - adfnmc.ui - ErrorHandlerImpl - reportException] Unable to retrieve String at index 2
    [WARNING - adfnmc.ui - ErrorHandlerImpl - reportException]
    [FINE - adfnmc.ui - MessageBox - show] message=oracle.adfnmc.AMCJboException: ADF-MNC-60109: Error retrieving sequence parameters for
    sequence S_SIEBELMOBILE_S_ORG_EXT
    [FINE - adfnmc.ui - MessageBox - show] oracle.adfnmc.java.sql.SQLException: net.rim.device.api.database.DataTypeException:Datatype mismatch
    [FINE - adfnmc.ui - MessageBox - show] Unable to retrieve String at index 2

    >
    >
    using 10gR2 on Sun-Solaris. Getting consistently "db file parallel read" over 35 ms as an average wait for the past few months. No performance issues as such.
    Using RAID 1+0. DB Size is 2 TB. Transactions are OLTP/Batch
    Is this metric high or normal. How to justify that..
    Looking at your results it's not really possible to say.
    db file parallel read is a request for a number of randomly distirbuted blocks, and the time for a read is the time for the last block of the set to be returned.
    Without knowing how many blocks are being requested at a time you can't really determine what constitutes a reasonable time. Given that you say OLTP + Batch, and have a large volume of scattered reads, it's quite possible that you have some queries on the Batch side doing very large index range scans - which would allow for some very large db file parallel reads.
    I take it from the use of statspack that you're not licensed for the diagnostic and performance packs; it would be easy to query v$active_session_history to get some idea of the number of blocks per request as this is given by the P2 parameter. As it is. you may be able to get a rough idea by messing about with the various "physical read" numbers in the Instance Activity section of statspack.
    Regards
    Jonathan Lewis

  • Do I use JFrame or JDialog?

    Hi,
    I wanted to create a dialog which allows me to have two JTextArea's. In one list I list possible selection for the user. In the other text area, all the files the user selected will be in the text area. There will be two buttons for removal/addition of these items from the second text area. When you hit the OK button the owner of the dialog needs to grab that info.
    Can an extension of a JDialog do this? Would it be suited for this? Or should I use an extension of a JFrame?
    thanks for any help in advance,
    Geoff

    I would use a JList. The Swing tutorial on "How to Use Lists" gives an example of how to add/remove items from a single list. Changing this to work with two lists should be easy:
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html#mutable

  • [b]Using audioclips in JFrame[/b]

    hey!!!!!!
    i want to know how to use audio clips in a jframe.
    i know how to use in the applet.
    plese help me with steps.

    In the future Swing related questions should be posted on the Swing forum.
    Read the tutorial on [url http://java.sun.com/docs/books/tutorial/]Sound. It highlights the differences between an applet and application.

  • Validating enabled and disabled menu bar in JInternalFrame

    hi,
    everybody.
    i have created a main window using JInternalFrame and JDesktopPane. The window has a menu bar in which document menu is used for closing the main window, while employee menu is used for adding new frame for the employee. while the login frame is displayed when the application is executed.
    my problem is, i want to validate that before login process, employee menu should be disabled, and after login is performed employee menu is enabled.
    the following is my code.
    please reply me as i am stucked with it.
    waiting for the reply
    thanks in advance.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    public class InternalFrameDemo extends JFrame implements ActionListener
    JDesktopPane desktop;
    public InternalFrameDemo()
    super("InternalFrameDemo");
    int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset*2, screenSize.height - inset*2);
    desktop = new JDesktopPane();
    setContentPane(desktop);
    desktop.setBackground(Color.white);
    setJMenuBar(createMenuBar());
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    createLogin();
    public JMenuBar createMenuBar()
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Document");
    menu.setMnemonic(KeyEvent.VK_D);
    menuBar.add(menu);
    JMenuItem menuItem = new JMenuItem("Quit");
    menuItem.setMnemonic(KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("quit");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    JMenu employee = new JMenu("Employee");
    employee.setMnemonic(KeyEvent.VK_E);
    employee.setActionCommand("employee");
    menuBar.add(employee);
    JMenuItem additem = new JMenuItem("Add");
    additem.setMnemonic(KeyEvent.VK_A);
    additem.setActionCommand("add");
    additem.addActionListener(this);
    employee.add(additem);
    return menuBar;
    public void actionPerformed(ActionEvent ae)
    String str = ae.getActionCommand();
    if(str.equals("add"))
    System.out.println("Employee Form Invoked");
    createEmployee();
    else if(str.equals("quit"))
    quit();
    public void createEmployee()
    MyEmployeeFrame employeeframe = new MyEmployeeFrame();
    employeeframe.setVisible(true);
    desktop.add(employeeframe);
    try
    employeeframe.setSelected(true);
    catch(Exception e)
    public void createLogin()
    MyLogin loginframe = new MyLogin();
    loginframe.setVisible(true);
    desktop.add(loginframe);
    try
    loginframe.setSelected(true);
    catch(Exception e){}
    public void quit()
    System.exit(0);
    private static void createAndShowGUI()
    JFrame.setDefaultLookAndFeelDecorated(true);
    InternalFrameDemo frame = new InternalFrameDemo();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,600);
    frame.setVisible(true);
    public static void main(String a[])
    createAndShowGUI();
    class MyEmployeeFrame extends JInternalFrame implements ActionListener
    JFrame employeeframe;
    JLabel labelfirstname;
    JLabel labellastname;
    JLabel labelage;
    JLabel labeladdress;
    JLabel labelcity;
    JLabel labelstate;
    JTextField textfirstname;
    JTextField textlastname;
    JTextField textage;
    JTextField textaddress;
    JTextField textcity;
    JTextField textstate;
    JButton buttonsave;
    FileOutputStream out;
    PrintStream p;
    String strfirstname,strlastname,strage,straddress,strcity,strstate;
    GridBagLayout gl;
    GridBagConstraints gbc;
    public MyEmployeeFrame()
    super("Employee Details",true,true,true,true);
    setSize(500,400);
    labelfirstname = new JLabel("First Name");
    labellastname = new JLabel("Last Name");
    labelage = new JLabel("Age");
    labeladdress = new JLabel("Address");
    labelcity = new JLabel("City");
    labelstate = new JLabel("State");
    textfirstname = new JTextField(10);
    textlastname = new JTextField(10);
    textage = new JTextField(5);
    textaddress = new JTextField(15);
    textcity = new JTextField(10);
    textstate = new JTextField(10);
    buttonsave = new JButton("Save");
    gl = new GridBagLayout();
    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 3;
    gl.setConstraints(labelfirstname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 3;
    gl.setConstraints(textfirstname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 5;
    gl.setConstraints(labellastname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 5;
    gl.setConstraints(textlastname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 7;
    gl.setConstraints(labelage,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 7;
    gl.setConstraints(textage,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 9;
    gl.setConstraints(labeladdress,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 9;
    gl.setConstraints(textaddress,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 11;
    gl.setConstraints(labelcity,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 11;
    gl.setConstraints(textcity,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 13;
    gl.setConstraints(labelstate,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 13;
    gl.setConstraints(textstate,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 3;
    gbc.gridy = 17;
    gl.setConstraints(buttonsave,gbc);
    Container contentpane = getContentPane();
    contentpane.setLayout(gl);
    contentpane.add(labelfirstname);
    contentpane.add(textfirstname);
    contentpane.add(labellastname);
    contentpane.add(textlastname);
    contentpane.add(labelage);
    contentpane.add(textage);
    contentpane.add(labeladdress);
    contentpane.add(textaddress);
    contentpane.add(labelcity);
    contentpane.add(textcity);
    contentpane.add(labelstate);
    contentpane.add(textstate);
    contentpane.add(buttonsave);
    buttonsave.addActionListener(this);
    public void reset()
    textfirstname.setText("");
    textlastname.setText("");
    textage.setText("");
    textaddress.setText("");
    textcity.setText("");
    textstate.setText("");
    public void actionPerformed(ActionEvent ae)
    String str = ae.getActionCommand();
    System.out.println(str);
    if(str.equalsIgnoreCase("Save"))
    try
    out = new FileOutputStream("myfile.txt",true);
    p = new PrintStream( out );
    strfirstname = textfirstname.getText();
    strlastname = textlastname.getText();
    strage = textage.getText();
    straddress = textaddress.getText();
    strcity = textcity.getText();
    strstate = textstate.getText();
    p.print(strfirstname+"|");
    p.print(strlastname+"|");
    p.print(strage+"|");
    p.print(straddress+"|");
    p.print(strcity+"|");
    p.println(strstate);
    System.out.println("Record Saved");
    reset();
    p.close();
    catch (Exception e)
    System.err.println ("Error writing to file");
    class MyLogin extends JInternalFrame implements ActionListener
    JFrame loginframe;
    JLabel labelname;
    JLabel labelpassword;
    JTextField textname;
    JPasswordField textpassword;
    JButton okbutton;
    String name = "";
    FileOutputStream out;
    PrintStream p;
    Date date;
    GregorianCalendar gcal;
    GridBagLayout gl;
    GridBagConstraints gbc;
    public MyLogin()
    super("Login",true,true,true,true);
    setSize(400,300);
    gl = new GridBagLayout();
    gbc = new GridBagConstraints();
    labelname = new JLabel("User");
    labelpassword = new JLabel("Password");
    textname = new JTextField("",9);
    textpassword = new JPasswordField(5);
    okbutton = new JButton("OK");
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 5;
    gl.setConstraints(labelname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 2;
    gbc.gridy = 5;
    gl.setConstraints(textname,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 10;
    gl.setConstraints(labelpassword,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 2;
    gbc.gridy = 10;
    gl.setConstraints(textpassword,gbc);
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 1;
    gbc.gridy = 15;
    gl.setConstraints(okbutton,gbc);
    Container contentpane = getContentPane();
    contentpane.setLayout(gl);
    contentpane.add(labelname);
    contentpane.add(labelpassword);
    contentpane.add(textname);
    contentpane.add(textpassword);
    contentpane.add(okbutton);
    okbutton.addActionListener(this);
    public void reset()
    textname.setText("");
    textpassword.setText("");
    public void run()
    try
    String text = textname.getText();
    String blank="";
    if(text.equals(blank))
    System.out.println("First Enter a UserName");
    else
    if(text != blank)
    date = new Date();
    gcal = new GregorianCalendar();
    gcal.setTime(date);
    out = new FileOutputStream("log.txt",true);
    p = new PrintStream( out );
    name = textname.getText();
    String entry = "UserName:- " + name + " Logged in:- " + gcal.get(Calendar.HOUR) + ":" + gcal.get(Calendar.MINUTE) + " Date:- " + gcal.get(Calendar.DATE) + "/" + gcal.get(Calendar.MONTH) + "/" + gcal.get(Calendar.YEAR);
    p.println(entry);
    System.out.println("Record Saved");
    reset();
    p.close();
    catch (IOException e)
    System.err.println("Error writing to file");
    public void actionPerformed(ActionEvent ae)
    String str = ae.getActionCommand();
    if(str.equals("OK"))
    run();
    loginframe.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    I realize this post is from a few days ago, but if you're still looking for help:
    This is my first thought on how to do this. Unfortunately, it's a bit messy. JMenuItems can be enabled and disabled but JMenus don't have this option...
    public class InternalFrameDemo extends JFrame implements ActionListener
        JDesktopPane desktop;
        JMenuBar menuBar;
        public InternalFrameDemo()
         setJMenuBar(createMenuBar());
         desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
         createLogin();
        public JMenuBar createMenuBar()
         menuBar = new JMenuBar();
         JMenu menu = new JMenu("Document");
         menu.setMnemonic(KeyEvent.VK_D);
         menuBar.add(menu);
         JMenuItem menuItem = new JMenuItem("Quit");
         menuItem.setMnemonic(KeyEvent.VK_Q);
         menuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.ALT_MASK));
         menuItem.setActionCommand("quit");
         menuItem.addActionListener(this);
         menu.add(menuItem);
         JMenuItem additem = new JMenuItem("Add");
         additem.setMnemonic(KeyEvent.VK_A);
         additem.setActionCommand("add");
         additem.addActionListener(this);
         employee.add(additem);
         return menuBar;
        public void createLogin()
         MyLogin loginframe = new MyLogin( menuBar );
         loginframe.setVisible(true);
         desktop.add(loginframe);
         try
             loginframe.setSelected(true);
         catch(Exception e)
    class MyLogin extends JInternalFrame implements ActionListener
        JMenuBar menuBar;
        public MyLogin( JMenuBar menuBar1 )
         super("Login",true,true,true,true);
         menuBar = menuBar1;
        public void actionPerformed(ActionEvent ae)
         String str = ae.getActionCommand();
         if(str.equals("OK"))
             run();
             JMenu employee = new JMenu("Employee");
             employee.setMnemonic(KeyEvent.VK_E);
             employee.setActionCommand("employee");
             menuBar.add(employee);
             loginframe.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

  • Multiple JInternalFrames

    I am using several JInternalFrames within a single JFrame. As of now each JInternalFrame is an inner class within the JFrame class. I want to seperate each JInternalFrame into its own class. If I do this how do I get the button in one JInternalFrame to set another JInternalFrame to visable seeing how we have no global variable in Java. I want to create all JInteranlFrame at once inside the Main JFrame. I do not want to be recreating the JInternalFrames each time I want to display them.
    This is not the exact code but I hope it gives you an idea.
    class MainJFrame extends JFrame {
    JDesktopPane d1;
    JButton b1;
    InternalFrame_A a1 = new InternalFrame_A();
    InternalFrame_A b1 = new InternalFrame_A();
    d1.add(b1);
    b1 Action = setVisable(a1);
    class InternalFrame_A extends JInternalFrame {
    JButton A1;
    A1 Action = setVisable(b1);
    class InternalFrame_B extends JInternalFrame {
    JButton B1;
    B1 Action = setVisable(a1);
    }

    Sorry, let me try to clarify. This is an application with a main menu (MainFrame). You submit an action on this main menu (A button). This brings up a form (JInternalFram_A). After filling out this form and hitting the submit button (a1), another form or menu open (JInternalFrame_B). After doing something and hitting submit or cancel the main menu come back up. I meant setting focu not visability. When main menu (MainFrame) has focus all other JInternalFrames are hiden behind it. And likewise for other JInternalFrames. Basically you can only see 1 JInternalFrame at a time.
    Hopefully this helps.

  • How to keep Allways JFrame on top of JApplet?

    I have Japplet runs on the client side. after pressing buton on the applet
    a jframe pops up. but if i click on the japplet it hides under japplet.
    Any ways to keep this jframe on the top ? if i use jframe.keep always on the top will thought security exception. I know applets have some security issue to access local OS resources or permission. just need to know any possibitly to achive this somehow?
    thnx

    I don't think this is possible. Others feel free to correct me. Perhaps try signing the applet or setting the permissions in the policy file.
    You can use a JInternalFrame to keep the frame within the JApplet.

  • Changing L&F on a JFrame?

    Hi all,
    I am currently writing my own look and feel, and I am having trouble with applying this on the JFrame-object. I managed to do this on the JInternalFrame (by using MetalInternalFrameUI)
    but I can not find a similiar class for a JFrame. I know that the look and feel for a JFrame is platform-dependent but still, I think it should be possible to do it. If not, is there any way to use JInternalFrame directly as a main container?
    Thank you,
    Regards Veroslav

    Hi Veroslav
    You need to tell the L&F manager what you are using. By simply calling
    JFrame.setDefaultLookAndFeelDecorated You are telling JFrames to decorate using the L&F if one is provided. If you have not provided one it will use the default L&F implementation.
    You need to do something like this.
    String rootpaneClassName = "com.yourcompany.YourRootPaneUI";
    UIManager.put("RootPaneUI", rootpaneClassName);
    UIManager.put(rootpaneClassName, Class.forName(rootpaneClassName));This will tell the L&F manager to use you rootpane UI class opposed to the default.
    You can then either set this to individual frames like so.
    try
    //get it to use our nice buttons and colours, loverly
    m_externalFrame.setUndecorated(true);
    m_externalFrame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
    RootPaneUI rpUI = (RootPaneUI)Class.forName(tmp).newInstance();
    m_externalFrame.getRootPane().setUI(rpUI);
    }catch(Exception ex)
    m_exceptionService.handleException(
    ex, "Cannot find Branded Look & Feel for Main Frame" );
    }You could alternatively write it directly into your L&F class to map all JRootPanes to use your RootPaneUI class
    Have a look at the Metal L&F classes ;) to get an idea about the RootPaneUI and TitlePane implementations.
    N35Sy

  • Using the swing worker to populate the data in to jtablle

    Hello, i am developing my 1st application in java swings , i have developed it but when i run a module which fetchces the data from the mysql and display it in jtable my swing gui got blank for some initial time, i was thinking for some progress bar type thing but when i came acroos google i found that i can use swing worker to load my GUI on time and in the back ground i can do the task of fetching the data from the data base and populating the Jtable, but i had done a lot of try but not succeded to implement the swing worker . Please help me to implement the swing worker :( . i am using the abstractTableModal to populating the jtable it is working fine but swing worker is not there .
    Scenerio is like this i have base frame on which i got 1 or more btton one of those button is Clients when i click on it a Jdialog box appears with the jtable . Pleae tell me how to implement the swing worker class between this. Pleaseeeeeeeeeeeeeeeeeeeeee :( I am help less now .

    Fahim i want to display some photograph in to a swing application after fetching these photo graph from the database table , i dont know what swing component will be better for it and i m designing this in netbeans , so please assist me with that , how to go now and please note that it is dynamic so component should be like that :(. i m trying to create a photo album where i upload the multiple photograph first then i would like to show them each photograph will a text box when some one write some text in that text box and press enter i would like to save that text with that photo graph , I AM DONE WITH THE PHOTO UPLOADING TASK BUT DONT KNOW HOW TO DO THE REST LIKE DISPLAYING THE PHOTOGRAPH WITH THAT TEXT BOX .
    Edited by: kamal.java on Apr 27, 2012 8:59 AM

Maybe you are looking for

  • Can't move images in Survey mode

    I click on a folder and pull up a few images in Survey and am not able to move/re-arrange said images, on other folders it works as it should -- Sometimes it works sometimes it doesn't -- yes, I click on the image itself. Is this a bug?

  • How to persist TextInput text values?

    Can anyone provide a brief explanation of how to persist text values? Description: Stuff written into a TextInput field does not persist when moving to another frame, and back again. Example: Frame 1: Put a TextInput component on the stage. Frame 1:

  • How to Copy SapBouicom.dll to destination folder

    Hi, I am using .net 2005 to create an installer for the addon. The probem is that sapbouicom.dll files are not getting copied  to the destination folder.Only installer and addon exes are extracted to the destination folder. If the dll files are manua

  • How do i get bejeweled on my ipod nano.

    how do i get bejeweled on my ipod nano. iv tried everything. please help.

  • How to indicate the object of the super Class ?

    hello, I need to notify when one dialog is close to the class that generated it. Of course I do it from the method windowClosing() in the class WindowAdapter. But if I use "this" how parameter in the method, I noted the value is that of the inner ano