Results 1 to 5 of 5
  1. #1
    Pencil is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Exclamation Setting up a frame

    Hello everyone,

    As you can see this is my first post and i was just wondering how you set up a JFrame with contained components.

    Basically i want to have them in this order:

    Canvas BELONGS TO: DesktopFrame (JInternalFrame).
    JInternalFrame (ifrmTools) BELONGS TO: DesktopFrame (JInternalFrame).
    DesktopFrame (JInternalFrame) BELONGS TO: dpDesktop (DesktopPane).
    dpDesktop (DesktopPane) BELONGS TO: frmMain (JFrame).

    But if you didnt understand that then i will try to break it down.

    Basically i want to have a JFrame, that on it, has a canvas and an internal frame called ifrmTools. I want the Tools frame (internal frame) to float over the canvas so they can pick a tool to draw on the canvas with. Like a simple PAINT program.

    Here is my issue, i have code, but it wont show the InternalFrame that is called 'ifrmTools' however it shows the Canvas.

    Below is my code:
    Java Code:
    import java.awt.Canvas;
    import java.awt.Color;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    
    public class Create {
        private double currentVersion = 1.0;
        public JFrame frmMain = new JFrame("Welcome " + currentVersion);
        public JDesktopPane dpDesktop = new JDesktopPane();
        public JInternalFrame ifrmDesktop = new JInternalFrame();
        public JInternalFrame ifrmTools = new JInternalFrame("Tools");
        public Canvas cCanvas = new Canvas();
    
        public void createAll() {
            createAndAddCanvas();
            createAndAddToolsFrame();
            createAndAddDesktopFrame();
            createAndAddDesktopPane();
            createAndAddMainFrame();
        }
    
        public void createAndAddCanvas() {
            cCanvas.setBackground(Color.WHITE);
            ifrmDesktop.add(cCanvas);
        }
    
        public void createAndAddToolsFrame() {
            ifrmTools.setResizable(false);
            ifrmTools.setBounds(10, 10, 105, 250);
            ifrmTools.setVisible(true);
            ifrmDesktop.add(ifrmTools);
        }
    
        public void createAndAddDesktopFrame() {
            ifrmDesktop.setResizable(false);
            ifrmDesktop.setBorder(null);
            ifrmDesktop.setClosable(false);
            ifrmDesktop.setMaximizable(true);
            ifrmDesktop.setVisible(true);
            dpDesktop.add(ifrmDesktop);
        }
    
        public void createAndAddDesktopPane() {
            dpDesktop.setVisible(true);
            frmMain.add(dpDesktop);
        }
    
        public void createAndAddMainFrame() {
            frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frmMain.setSize(800, 600);
            frmMain.setLocation(100, 100);
            frmMain.setVisible(true);
        }
    
    }
    And obviously the main class calls this with a simple:

    Java Code:
    public class Main {
    
        public static void main(String[] args) {
            Create c = new Create();
            c.createAll();
        }
    
    }
    Thanks in advance,

    Pencil.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You shouldn't mix AWT components with Swing components. So get rid of the Canvas and use a JFrame or similar instead. It does all that Canvas does and more. For your floating tools, why not just use a JToolBar?

    e.g., toolbar tutorial

  3. #3
    Pencil is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    Ok man cool, cheers for the advice i really appreciate it.

    Just out of consideration, howcomes you shouldn't mix them?

    Pencil.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    Mixing heavy and light components

    You may also find this interesting
    Painting in AWT and Swing

    db

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Fubarable View Post
    You shouldn't mix AWT components with Swing components. So get rid of the Canvas and use a JFrame or similar instead. It does all that Canvas does and more. For your floating tools, why not just use a JToolBar?
    Oops, I meant JPanel, not JFrame above.

Similar Threads

  1. Replies: 7
    Last Post: 11-02-2009, 06:31 PM
  2. Setting frame size to the size of an image
    By Yoruichi in forum AWT / Swing
    Replies: 5
    Last Post: 04-22-2009, 04:37 PM
  3. GUI new frame
    By billbo123 in forum New To Java
    Replies: 15
    Last Post: 03-02-2009, 04:24 AM
  4. Setting the DSN
    By tim in forum JDBC
    Replies: 1
    Last Post: 02-14-2008, 09:55 PM
  5. Help with setting up please
    By BlitzA in forum New To Java
    Replies: 6
    Last Post: 12-29-2007, 12:54 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
  •