Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JFrame

Posted on 1998-11-04
4
Medium Priority
?
771 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 90 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

722 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