Results 1 to 17 of 17

Thread: JInternal Frame help

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    JInternal Frame help

    I need help with this JInternal frame stuff. I had it working when it was just a normal frame, but it showed up in the task bar, and I didn't want that. The problem is, it's not showing up..

    this is in the actionPerformed method and it calls this if the user selects find and replace in the edit menu

    Code:
     else if ((ae.getSource() == findAndReplace))
    	 {
    		
    		   new processFindAndReplace();
    	 }


    if the user selects it, it invokes this new class trying to construct a new internal frame
    Code:
     class processFindAndReplace extends JFrame implements ActionListener
     {
        public processFindAndReplace()
        {
    	 JInternalFrame jif = new JInternalFrame();
    	 JLabel lblFind = new JLabel("Find what:");
    	 JTextField txtFind = new JTextField(20);
    	 JButton btnFind = new JButton("Find");
    	 JLabel lblReplace = new JLabel("Replace with:");
    	 JTextField txtReplace = new JTextField(20);
    	 JButton btnReplace = new JButton("Replace");
    	 JButton btnCancel = new JButton("Cancel");
    	 
    	 Container pane2 = getContentPane();
    	 pane2.add(lblFind);
    	 pane2.add(txtFind);
    	 pane2.add(btnFind);
    	 pane2.add(lblReplace);
    	 pane2.add(txtReplace);
    	 pane2.add(btnReplace);
    	 pane2.add(btnCancel);
    	 jif.setContentPane(pane2);
    	 pane2.setLayout(new FlowLayout());
    	 
    	 jif.setResizable(false);
    	 jif.setMaximizable(false);
    	 jif.setClosable(true);
    	 jif.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	 jif.setSize(250,250);
    	 jif.setVisible(true);
        }
       
        public void actionPerformed(ActionEvent ae)
        {
        }
    	 
    	 
     }

    Could someone help me get this thing to be visible?

    Note: I don't need help with the code that goes in the actionPerformed, I just want the stupid thing to show up.

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: JInternal Frame help

    I would use a JDesktopPane instead. While it is not required that internal frames be use with a JDesktopPane a JDesktopPane adds direct support for managing a collection of JInternalFrames in layers.

  3. #3

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JInternal Frame help

    I don't know if I mentioned it, but im using this class as an inner class, it has a super class called TextEditor. Anyways, I tryed using the JDesktopPane and it gave me an error saying: IllegalArgumentException: adding containenrs parent to itself.....also it's still not showing up..


    Here is the code after modifications:

    Code:
     class processFindAndReplace extends JFrame implements ActionListener
     {
        public processFindAndReplace()
        {
    	 JDesktopPane dpane = new JDesktopPane();
    	 JInternalFrame jif = new JInternalFrame();
    	 JLabel lblFind = new JLabel("Find what:");
    	 JTextField txtFind = new JTextField(20);
    	 JButton btnFind = new JButton("Find");
    	 JLabel lblReplace = new JLabel("Replace with:");
    	 JTextField txtReplace = new JTextField(20);
    	 JButton btnReplace = new JButton("Replace");
    	 JButton btnCancel = new JButton("Cancel");
    	 
    	 Container pane2 = getContentPane();
    	 pane2.add(lblFind);
    	 pane2.add(txtFind);
    	 pane2.add(btnFind);
    	 pane2.add(lblReplace);
    	 pane2.add(txtReplace);
    	 pane2.add(btnReplace);
    	 pane2.add(btnCancel);
    	 jif.setContentPane(pane2);
    	 pane2.setLayout(new FlowLayout());
    	 
    	 dpane.add(jif);
    	 jif.setResizable(false);
    	 jif.setMaximizable(false);
    	 jif.setClosable(true);
    	 jif.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	 jif.setSize(250,250);
    	 dpane.setSelectedFrame(jif);
    	 super.getContentPane().add(dpane);
    	 jif.setVisible(true);
        }
       
        public void actionPerformed(ActionEvent ae)
        {
        }
    	 
    	 
     }

  4. #4

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JInternal Frame help

    I know I have to somehow add it to the super classes container, but that's what I thought I did with:

    Code:
    super.getContentPane().add(dpane);

  5. #5

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JInternal Frame help

    Should I just create the internal frame in the super class and only make it visible when that one method is invoked in the actionPerformed?

  6. #6
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: JInternal Frame help

    Seems you want to use the desktop pane as the content pane of a JFrame. Just create the JDesktopPane and set the content pane of the JFrame. You still have in jif.setContentPane(pane2); which is not needed since you want to add the internal frames to the desktop pane not the frame itself.

  7. #7

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JInternal Frame help

    I don't think I will go this way...Do you think I should just create a JDialogBox?

    If so, could you tell my how to add the contents to it?

  8. #8
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: JInternal Frame help

    Posted by System_Error

    Do you think I should just create a JDialogBox?
    It depends. What was the internal frame initially to be used for?

    I suggested using a JDesktopPane because you were using internal frames. What are you actually trying to do? Take some kind of input from the user via an internal frame?

  9. #9

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JInternal Frame help

    Well, I wanted to create someone kind of dialog/frame when the user selected 'Find and Replace', but everytime I try the internal frame I've had problems. So I was wondering how a DialogBox would work. Yes, I do want use input, a string to search for and input on what to replace it with..I got all the methods ready for this but the GUI is just not being very nice.

    So do you think I should stick with JInternalFrame or go with a JDialog?

  10. #10
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: JInternal Frame help

    JDialog is the shortest and easiest route to take. Just use one of the static methods to pop it up instead of trying to construct a dialog from scratch. If you need help i will be around.

  11. #11
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: JInternal Frame help

    Take a trip on over to sun's docs http://java.sun.com/j2se/1.5.0/docs/api/ and look for the JOptionPane class under the javax.swing package. You will most likely want to use one of the static showInputDialog() methods.

  12. #12

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JInternal Frame help

    Thanks Dillenger. I'll try the tutorial and get back to ya.

  13. #13

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JInternal Frame help

    Ok...I tryed the JOptionPane after looking at the docs, but I think I'm still missing something since it's not showing up. I know it's something up with the arguments, but not sure what else I should add.

    Code:
     public void processFindAndReplace()
     {
       Container content = new Container();
       content.setLayout(new FlowLayout());
        JLabel lblFind = new JLabel("Find what:");
        JTextField txtFind = new JTextField(20);
        JButton btnFind = new JButton("Find");
        JLabel lblReplace = new JLabel("Replace with:");
        JTextField txtReplace = new JTextField(20);
        JButton btnReplace = new JButton("Replace");
        JButton btnCancel = new JButton("Cancel");
        
        
        content.add(lblFind);
        content.add(txtFind);
        content.add(btnFind);
        content.add(lblReplace);
        content.add(txtReplace);
        content.add(btnReplace);
        content.add(btnCancel);
        
     
        JOptionPane jop = new JOptionPane(content);
        jop.setSize(205,205);
        jop.show();
       
     }

  14. #14
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: JInternal Frame help

    Figure out how you want to trigger the dialog box to show. Say when a JButton is pressed. Hook the button to a class via addActionListener(new DialogListener(this)) passing in an instance of a class that implements the relevant listener interface or one that extends an adapter class. Also pass to the DialogListener class the current object so you can use that object as an arguement to one of the showInputDialog() methods contained in the JOptionPane class. If you notice all of the showInputDialog() methods take a Component as an arguement. The parent component.

  15. #15

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JInternal Frame help

    Ok thanks. I'll try that tommorow and get back to you.

  16. #16
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: JInternal Frame help

    I was bored so.....

    The following works but using a premade dialog box just aint gonna cut it since you seem to need multiple text fields to take the users input.
    Code:
     import java.awt.*; 
     import javax.swing.*; 
     import java.awt.event.*; 
    
     public class X extends JFrame{
      public static void main(String[] args){
        new X(); 
      }
       
       private JMenuBar jmb = new JMenuBar(); 
       private JMenu tools = new JMenu("Tools"); 
       private JMenuItem fr = new JMenuItem("Find and Replace"); 
    
      public X(){
       tools.add(fr); 
       jmb.add(tools); 
       setJMenuBar(jmb); 
       fr.addActionListener(new MenuItemListener(this));
      
       addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent we){
         System.exit(0); 
        }
      });
    
       setSize(400,300);
       setVisible(true); 
      }
     }
     
     class MenuItemListener implements ActionListener{
      private X x;
      public MenuItemListener(X x){
       this.x = x;  
      }
      
      public void actionPerformed(ActionEvent ae){
        Object selectedValue = JOptionPane.showInputDialog(x,"Input", "Find & Replace",JOptionPane.INFORMATION_MESSAGE); // gonna need a custom dialog :mad:
      }
     }

  17. #17

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JInternal Frame help

    Thank you so much, this helped me out A LOT.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width