Results 1 to 3 of 3
  1. #1
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Arranging components (JButtons) in a ContentPane of a JFrame

    Hi,
    I wanted to store my book chapter into a java frame, and I've created two buttons for two headings,
    Java Code:
    package learning;
    	import java.awt.*;
            import javax.swing.*;
    
    	class RequirementEngineering extends JPanel
    	{
    		
    		public static void main(String[] args)
    		{
    	JPanel customPanel = new RequirementEngineering();
    	JFrame frame = new JFrame("my window");
    	frame.getContentPane().add(customPanel ,BorderLayout.CENTER);
    	
    	JButton myButton=new JButton("Feasibility Study");
    	myButton.setPreferredSize(new Dimension(140,60));
    	customPanel.add(myButton);
    
    	JButton myButton2=new JButton("Feasibility Report");
    	myButton2.setPreferredSize(new Dimension(140,60));
    	//myButton2.setBounds(200, 200, 140, 60);
    	customPanel.add(myButton2);
    	myButtonb2.setLocation(180, 400);
    	
    	
    	
    	frame.setSize(700,700);
    	frame.setVisible(true);
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	//frame.pack();
    		}
    	}
    the gridLayout() argument is not present for JButton,
    Java Code:
    myButton2.setBound(); //(line #23)didn't work,
    I removed
    Java Code:
     frame.pack();//(line#32)
    and checked for once, and didn't get its bounds yet

    EDITED to add: sorry my question is, how to place a JButton to a desired location.!.
    regards
    dhilip
    Last edited by noobplus; 09-27-2013 at 07:49 PM. Reason: editing conventions

  2. #2
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: Arranging components (JButtons) in a ContentPane of a JFrame

    Quote Originally Posted by noobplus View Post
    Hi,
    how to place a JButton to a desired location
    Hi I changed the layout of the ContentPane to null, and it is working fine.
    Java Code:
    customPanel.setLayout(null);
    regards
    dhilip

  3. #3
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: Arranging components (JButtons) in a ContentPane of a JFrame

    I've added
    Java Code:
     FeasibilityStudy fs=new FeasibilityStudy();
    and
    Java Code:
     myButton.addActionListener(new ActionListener() {
    		
    		@Override
    		public void actionPerformed(ActionEvent e) {
    			
    			JFrame miniFrame=new JFrame();
    			miniFrame.getContentPane().add(fs);
    			miniFrame.setVisible(true);
    			miniFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    			miniFrame.setSize(1200,700);
    		}
    	});
    where fs is another class in same package
    Java Code:
    package learning;
    
        import java.awt.Color;
            import java.awt.Graphics;
               import javax.swing.JPanel;
    public class FeasibilityStudy extends JPanel{
    
    	public void paintComponent(Graphics g)
    	{
    		super.paintComponent(g);
    		
    		g.drawString("this is under construction .", 20, 20);
    		
    	}
    
    }
    Can I add FeasibilityStudy panel into a tooltip for JButton?
    Can we create a tooltip for a JButton with a frame inside the tooltip?
    Edited to add: using a MouseMotionListener() ?
    Last edited by noobplus; 10-05-2013 at 07:57 PM. Reason: writing full code

Similar Threads

  1. Replies: 2
    Last Post: 04-29-2011, 04:44 AM
  2. Help with JButtons into JFrame
    By g6pd in forum New To Java
    Replies: 5
    Last Post: 03-10-2011, 05:49 AM
  3. Jbuttons stealing focus from other components
    By gib65 in forum AWT / Swing
    Replies: 14
    Last Post: 09-28-2010, 07:22 PM
  4. JFrame: JButtons in a grid
    By jackal in forum New To Java
    Replies: 2
    Last Post: 06-09-2010, 08:56 PM
  5. JSplitPane Arranging Components(JTree) Doubt
    By hemanthjava in forum AWT / Swing
    Replies: 0
    Last Post: 08-03-2008, 09:29 AM

Tags for this Thread

Posting Permissions

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