Results 1 to 5 of 5
Like Tree2Likes
  • 2 Post By gimbal2

Thread: WindowsBuilder and custom components

  1. #1
    SuperWoman's Avatar
    SuperWoman is offline Member
    Join Date
    Sep 2014
    Posts
    12
    Rep Power
    0

    Question WindowsBuilder and custom components

    Hello Guys,

    It appears that WindowBuilder (Eclipse/Java) only displays custom components if they are declared outside the main gui class of the app.

    Here's WindowBuilder in action in Design view... (note in the Component panel it doesn't list the second jpanel (the subclassed one)....
    WindowsBuilder and custom components-xzk4asu.png

    For example, in the code below, the custom JPanel is declared OUTSIDE the main class of the app.

    Java Code:
    package views;
    import java.awt.EventQueue;
    ...
     
    //---------------------------------------------------------------------------//
    //This is my subclassed jpanel for drawing declared OUTSIDE the main gui class.
    
    class MyJPanel extends JPanel
    {
        @Override
        public void paintComponent(Graphics g) 
        {
           super.paintComponent(g);
        }	
    }
    
    //---------------------------------------------------------------------------//
    
    
    //---------------------------------------------------------------------------//
    //This is the main class for the gui
    public class SandboxToo 
    {
    	private JFrame frame;
    	private JPanel panel;
    	private MyJPanel myPanel;
    	...
    And this will result in WindowBuilder displaying the custom JPanel in Design view.

    WindowsBuilder and custom components-bm303rn.png


    However, if you declare your custom JPanel INSIDE the main class of the gui:

    Java Code:
    package views;
     
    import java.awt.EventQueue;
     ...
    public class SandboxToo //This is the main class for the gui
    {
            // Now my custom JPanel is declared INSIDE the main gui class
    	class MyJPanel extends JPanel
    	{
    	    @Override
    	    public void paintComponent(Graphics g) 
    	    {
    	       super.paintComponent(g);
    	    }	
    	}	
    	private JFrame frame;
    	private JPanel panel;
    	private MyJPanel myPanel;
    Then WindowBuilder will NOT display the custom JPanel.
    WindowsBuilder and custom components-n3b7c6m.png


    Is this working as intended?
    As a beginner, I perceive value in having the declaring done INSIDE my main gui class for all sorts of reasons (which may be bad coding).

    What are your thoughts?

    Thanks!

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

    Default Re: WindowsBuilder and custom components

    My thoughts are that this is one of the reasons that novice programmers shouldn't use GUI builders. If you want to learn how to program a GUI, you have to write the code yourself.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: WindowsBuilder and custom components

    Credit to the OP though; usually when people use gui builders they don't WANT to understand, that is clearly not the case here.

    So do yourself a favor: if you really want to learn, stop using the GUI builder.
    KevinWorkman and Hamenopi like this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    Hamenopi is offline Nub
    Join Date
    Sep 2014
    Location
    Houston
    Posts
    8
    Rep Power
    0

    Default Re: WindowsBuilder and custom components

    Wow! A question with content and context. Wasn't sure if those existed anymore.

    I'm confused though, why exactly are you putting a class inside a class?

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: WindowsBuilder and custom components

    Anonymous classes and inner classes are quite a common practice in GUI code. The basic answer to your question is: "why not?".
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Components one over the other
    By Sutured in forum AWT / Swing
    Replies: 3
    Last Post: 09-11-2012, 06:35 PM
  2. Replies: 0
    Last Post: 09-12-2011, 01:06 PM
  3. Swing components vs. custom painting
    By Cruncher in forum New To Java
    Replies: 6
    Last Post: 05-06-2010, 07:16 AM
  4. Replies: 2
    Last Post: 07-22-2007, 12:01 PM
  5. Gui Components
    By Marty in forum New To Java
    Replies: 1
    Last Post: 05-28-2007, 04:04 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
  •