Results 1 to 5 of 5
  1. #1
    s4nti4go is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default Issues with panels and borders

    Hello, I'm new to this forum.

    The thing is that I'm trying to border a panel (by creating a subclass of Panel), but instead of that, this is what I'm getting:



    And here's the code of the BorderedPanel class:

    Java Code:
    import java.awt.*;
    
    public class BorderedPanel extends Panel {
    	
    	BorderedPanel(){
    		super();
    			}
    	
    	public Insets insets(){
    		return new Insets(5,5,5,5);
    	}
    	
    	public void paint(Graphics g){
    		Dimension d = getSize();
    		g.draw3DRect(0,0,d.height-1,d.width-1,true);
    	}
    }
    And finally, a piece of code where I use this (pretty much all the same for every group of Textfields/Labels, which are all inside a Panel, not BorderedPanel!).

    Java Code:
    [...]
    PROP.add(P_PVT);
    PROP.add(P_UHSGA);
    PROP.add(P_X);
    PROP.setLayout(new GridLayout(4,1));
    add(PROP,BorderLayout.EAST);
    [...]
    Thank you in advance!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default

    I'd be interested to see an SSCCE that demonstrates this problem. Try to make it as small as possible- a single JPanel with a single JButton or something.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    s4nti4go is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    Ok. Heres the code:

    Java Code:
    import java.awt.*;
    
    public class Test extends Frame{
    
    	BorderedPanel p = new BorderedPanel();
    	TextField t = new TextField(8);
    	Label l = new Label("Hello!");
    	
    	public Test(String title){
    		super(title);
    		p.add(t,BorderLayout.EAST);
    		p.add(l,BorderLayout.WEST);
    		add(p);
    	}
    	
    	public static void main(String[] args){
    		Frame f = new Test("SSCCE");
    		f.setBounds(0,0,200,100);
    		f.show();
    	}
    }
    .

    BorderedPanel is exactly the same here. Plus, a pic:



    I ran twice the program, to show you howd it look at its normal size (200x100), and maximized (1440x990).

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default

    Hm, that doesn't compile for me. I get the following error:

    Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
    at java.awt.Container.checkNotAWindow(Unknown Source)
    at java.awt.Container.addImpl(Unknown Source)
    at java.awt.Container.add(Unknown Source)
    at Test.<init>(Test.java:13)
    at Test.main(Test.java:17)


    Also, is there a reason you're using AWT and not Swing?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    s4nti4go is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    Well, Ive been learning Java from a book, which introduced only the AWT library. But, after having done a little research, Ill switch to Swing.

    About your error, I honestly dont have idea.

Similar Threads

  1. Deleting panels
    By dilpreet28 in forum New To Java
    Replies: 13
    Last Post: 08-11-2010, 10:23 AM
  2. Borders
    By sessomw5098 in forum New To Java
    Replies: 2
    Last Post: 04-21-2010, 06:00 AM
  3. Replies: 0
    Last Post: 11-12-2009, 11:15 AM
  4. resizeable panels
    By simo_mon in forum AWT / Swing
    Replies: 4
    Last Post: 07-29-2009, 02:45 AM
  5. Applets painting outside borders in web browsers
    By sirdori in forum New To Java
    Replies: 2
    Last Post: 11-20-2008, 07:14 PM

Posting Permissions

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