Solved

JFrame

Posted on 1998-11-04
4
744 Views
Last Modified: 2013-11-23
Hi,

I created a JFrame with a JButton.If i pressed the JButton
I am calling a JInternalFrame .
Here My problem is once the JInternalFrame comes ,the
JButton in the JFrame is not visible.
Is there any method to avoid this.How will solve this problem.

Here is My code.

JFrame With Button
-------------------------------
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class Jmain extends JFrame implements ActionListener
{
      JLabel l1,l2,l3,l4;
      JTextField tf1,tf2;
      JPasswordField pf;
      JButton b1,b2;
      JDesktopPane desktop;
      Rectangle r1,r2,r3,r4,r5,r6,r7,r8,r9,r10;
      //passcheck pc;
      //error ee;
      //boolean bool1,bool2;
      public Jmain()
      {
            int inset = 50;
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setBounds(inset, inset,
              screenSize.width - inset*2,
              screenSize.height-inset*2);
            /*l1=new JLabel("CheckIT");
            l2=new JLabel("AdminiName");
            l3=new JLabel("AdminiID");
            l4=new JLabel("Password");
            tf1=new JTextField(25);
            tf2=new JTextField(25);
            pf=new JPasswordField(25);
            pf.setEchoChar('*');*/
            b1=new JButton("UserDetail");
            b1.addActionListener(this);
            b1.setBounds(30,235,150,30);
            getContentPane().add(b1);
            l2=new JLabel("AdminiName");
            l2.setBounds(100,100,20,30);
            getContentPane().add(l2);
            l2.setVisible(false);
            /*b2=new JButton("QuestionBank");
            b1.addActionListener(this);
            //b2.addActionListener(this);
            getContentPane().add(l1);
            getContentPane().add(l2);
            getContentPane().add(tf1);
            getContentPane().add(l3);
            getContentPane().add(tf2);
            getContentPane().add(l4);
            getContentPane().add(pf);
            getContentPane().add(b1);
            getContentPane().add(b2);
            tf1.setSelectionColor(Color.blue);*/
            setVisible(true);
            addWindowListener(new winHandle());
      
      }
      class winHandle extends WindowAdapter
      {
            public void windowClosing(WindowEvent e)
            {
                  System.exit(0);
            }
      }
      public void actionPerformed(ActionEvent e)
      {
            String s=e.getActionCommand();
            if(s.equals("UserDetail"))
            {
                  System.out.println("Before");
                  
            desktop = new JDesktopPane();
            JUserDetail in=new JUserDetail();
            desktop.add(in);
            try{
                  in.setSelected(true);
            }catch(Exception ee){}
            setContentPane(desktop);
            setVisible(true);
            System.out.println("After");
            
            }
            if(s.equals("QuestionBank"))
            {
                  System.out.println("QuestionBank");
            }
      }
      /*public void paint(Graphics p)
      {
            
            Font f1=new Font("TimesRoman",Font.BOLD+Font.ITALIC,25);
            Font f2=new Font("TimesRoman",Font.BOLD,15);
            l1.setFont(f1);
            r1=new Rectangle(150,50,100,30);
            l1.setBounds(r1);
            r2=new Rectangle(80,100,100,30);
            l2.setBounds(r2);
            l2.setFont(f2);
            r3=new Rectangle(220,103,100,24);
            tf1.setBounds(r3);
            r4=new Rectangle(80,140,100,30);
            l3.setBounds(r4);
            l3.setFont(f2);
            r5=new Rectangle(220,143,100,24);
            tf2.setBounds(r5);
            r6=new Rectangle(80,180,100,30);
            l4.setBounds(r6);
            l4.setFont(f2);
            r7=new Rectangle(220,183,100,24);
            pf.setBounds(r7);
            r8=new Rectangle(30,235,150,30);
            b1.setBounds(r8);
            r9=new Rectangle(210,234,150,30);
            b2.setBounds(r9);
            
      }*/
            public static void main(String arg[])
            {
                  Jmain j=new Jmain();
                  j.show();
            }
      }

Here only one JButton  Userdetail is  visible.If i click that JButton it will call another JInternalFrame.

JInternalFrame
----------------------
import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JUserDetail extends JInternalFrame implements ActionListener
{
      JLabel l1,l2,l3,l4,l5,l6;
      JTextField tf1,tf2,tf3,tf4;
      JTextArea ta;
      JCheckBox cb;
      JButton b1,b2,b3,b4,b5,b6;
      JScrollPane jp;
      Rectangle r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r18;
      public JUserDetail()
      {
            super("UserSecurityDetail",true,true,true,true);
            Font f=new Font("TimesRoman",Font.BOLD+Font.ITALIC,15);
            l1=new JLabel("User Name");
            l1.setFont(f);
            l1.setBounds(50,10,100,30);
            getContentPane().add(l1);
            tf1=new JTextField();
            tf1.setBounds(150,12,120,28);
            getContentPane().add(tf1);
            l2=new JLabel("User No");
            l2.setBounds(50,60,100,30);
            l2.setFont(f);
            getContentPane().add(l2);
            tf2=new JTextField();
            tf2.setBounds(150,62,120,28);
            getContentPane().add(tf2);
            l3=new JLabel("Password");
            l3.setBounds(50,110,100,30);
            l3.setFont(f);      
            getContentPane().add(l3);
            tf3=new JTextField();
            tf3.setBounds(150,112,120,28);
            getContentPane().add(tf3);
            l4=new JLabel("User Level");
            l4.setBounds(50,160,100,30);
            l4.setFont(f);      
            getContentPane().add(l4);
            tf4=new JTextField();
            tf4.setBounds(150,162,120,28);
            getContentPane().add(tf4);
            l5=new JLabel("Active");
            l5.setBounds(50,210,100,30);
            l5.setFont(f);      
            getContentPane().add(l5);
            cb=new JCheckBox();
            cb.setBounds(150,212,30,30);
            getContentPane().add(cb);
            l6=new JLabel("User Details/Remarks");
            l6.setBounds(325,20,200,30);
            l6.setFont(f);
            getContentPane().add(l6);
            ta=new JTextArea();
            jp=new JScrollPane(ta);
            jp.setBounds(300,50,250,75);
            getContentPane().add(jp);
            b1=new JButton("ADD");
            b1.setBounds(5,300,100,30);
            getContentPane().add(b1);
            b2=new JButton("EDIT");
            b2.setBounds(105,300,100,30);
            getContentPane().add(b2);
            b3=new JButton("DELETE");
            b3.setBounds(205,300,100,30);
            getContentPane().add(b3);
            b4=new JButton("SAVE");
            b4.setBounds(305,300,100,30);
            getContentPane().add(b4);
            b5=new JButton("EXIT");
            b5.setBounds(405,300,100,30);
            getContentPane().add(b5);
            b5.addActionListener(this);
            b6=new JButton("RESET");
            b6.setBounds(505,300,100,30);
            getContentPane().add(b6);
            JButton b7=new JButton("Junk");
            b7.setBounds(550,300,10,10);
            getContentPane().add(b7);
            b7.setVisible(false);
            setSize(615,400);
            setLocation(250,10);
                        
      }
            public void actionPerformed(ActionEvent e)
            {
                  setVisible(false);
                  dispose();
            }
      
      
}
if i press the JButton this JInternalFrame is coming but the JButton is not visible.
0
Comment
Question by:senthil_krn
  • 2
4 Comments
 
LVL 7

Expert Comment

by:conick
ID: 1226913

If you could include your code it may help someone determine how to avoid your problem.

You can set the size, with setSize(Dimension d) and the location, with setLocation(Point p), of the internal frame within the container.  That way you can put your internal frame somewhere that the button isnt.

If that doenst help include your code and someone with more experience would surely help you.

0
 

Author Comment

by:senthil_krn
ID: 1226914
Edited text of question
0
 

Author Comment

by:senthil_krn
ID: 1226915
Adjusted points to 30
0
 

Accepted Solution

by:
pocram earned 30 total points
ID: 1226916
this is a correct code for Jmain:

you have to initialyse your JDesktopPane in Jmain, and not any more in your actionPerformed method, and define it as the ContentPane of your JFrame!
PS:no modifications for your JInternalFrame


    public class Jmain extends JFrame implements ActionListener
    {
    JLabel l1,l2,l3,l4;
    JTextField tf1,tf2;
    JPasswordField pf;
    JButton b1,b2;
    JDesktopPane desktop = new JDesktopPane();
    Rectangle r1,r2,r3,r4,r5,r6,r7,r8,r9,r10;
    //passcheck pc;
    //error ee;
    //boolean bool1,bool2;
    public Jmain()
    {
    int inset = 50;
    setContentPane(desktop);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset,
      screenSize.width - inset*2,
      screenSize.height-inset*2);
    /*l1=new JLabel("CheckIT");
    l2=new JLabel("AdminiName");
    l3=new JLabel("AdminiID");
    l4=new JLabel("Password");
    tf1=new JTextField(25);
    tf2=new JTextField(25);
    pf=new JPasswordField(25);
    pf.setEchoChar('*');*/
    b1=new JButton("UserDetail");
    b1.addActionListener(this);
    b1.setBounds(30,235,150,30);
    getContentPane().add(b1);
    l2=new JLabel("AdminiName");
    l2.setBounds(100,100,20,30);
    getContentPane().add(l2);
    l2.setVisible(false);
    /*b2=new JButton("QuestionBank");
    b1.addActionListener(this);
    //b2.addActionListener(this);
    getContentPane().add(l1);
    getContentPane().add(l2);
    getContentPane().add(tf1);
    getContentPane().add(l3);
    getContentPane().add(tf2);
    getContentPane().add(l4);
    getContentPane().add(pf);
    getContentPane().add(b1);
    getContentPane().add(b2);
    tf1.setSelectionColor(Color.blue);*/
    setVisible(true);
    addWindowListener(new winHandle());

    }
    class winHandle extends WindowAdapter
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    }
    public void actionPerformed(ActionEvent e)
    {
    String s=e.getActionCommand();
    if(s.equals("UserDetail"))
    {
    System.out.println("Before");

    JUserDetail in=new JUserDetail();
    desktop.add(in);
    try{
    in.setSelected(true);
    }catch(Exception ee){}
    setContentPane(desktop);
    setVisible(true);
    System.out.println("After");

    }
    if(s.equals("QuestionBank"))
    {
    System.out.println("QuestionBank");
    }
    }
    /*public void paint(Graphics p)
    {

    Font f1=new Font("TimesRoman",Font.BOLD+Font.ITALIC,25);
    Font f2=new Font("TimesRoman",Font.BOLD,15);
    l1.setFont(f1);
    r1=new Rectangle(150,50,100,30);
    l1.setBounds(r1);
    r2=new Rectangle(80,100,100,30);
    l2.setBounds(r2);
    l2.setFont(f2);
    r3=new Rectangle(220,103,100,24);
    tf1.setBounds(r3);
    r4=new Rectangle(80,140,100,30);
    l3.setBounds(r4);
    l3.setFont(f2);
    r5=new Rectangle(220,143,100,24);
    tf2.setBounds(r5);
    r6=new Rectangle(80,180,100,30);
    l4.setBounds(r6);
    l4.setFont(f2);
    r7=new Rectangle(220,183,100,24);
    pf.setBounds(r7);
    r8=new Rectangle(30,235,150,30);
    b1.setBounds(r8);
    r9=new Rectangle(210,234,150,30);
    b2.setBounds(r9);

    }*/
    public static void main(String arg[])
    {
    Jmain j=new Jmain();
    j.show();
    }
    }

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question