Results 1 to 5 of 5
  1. #1
    Warhorsei is offline Member
    Join Date
    Jun 2008
    Posts
    3
    Rep Power
    0

    Default JPanel / layout problems

    Hey folks.. I am having a problem with using a few of the layouts within a JPanel. For some reason if I use flowlayout or gridlayout the components of the panel display. If i use springlayout, boxlayout, or absolute positioning the panel does not display. I have the panel embedded in a JFrame. Here is the code snippet for one of the panels in the application...

    If i change the first line to modePanel = new JPanel(); it displays FYI

    // Mode Panel Coding
    modePanel = new JPanel(null);
    lblModeSelect = new JLabel("Select a mode");
    lblModeSelect.setFont(lblModeSelect.getFont().deri veFont(14.0f));
    cmbModeSelect = new JComboBox(modeArray);
    cmbModeSelect.setSelectedIndex(0);
    // x, y, width, height
    modePanel.add(lblModeSelect);
    modePanel.add(cmbModeSelect);
    lblModeSelect.setSize(lblModeSelect.getPreferredSi ze());
    //lblModeSelect.setVisible(true);
    modePanel.setSize(100,50);
    System.out.println(lblModeSelect.getSize());
    lblModeSelect.setBounds(1, 1, 55, 10);
    cmbModeSelect.setBounds(1, 20, 55, 10);
    content.add(modePanel);
    content.validate();
    //modePanel.setVisible(true);
    content.layout.putConstraint(SpringLayout.WEST, modePanel,
    1, SpringLayout.WEST, content);
    content.layout.putConstraint(SpringLayout.NORTH, modePanel,
    1, SpringLayout.NORTH, content);
    cmbModeSelect.addActionListener(this);

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Have you tried to set its layout to null? instead of Setting the LayoutManager to null(@ JPanel parameter)

    eg.
    Java Code:
    this.setLayout(null);
    freedom exists in the world of ideas

  3. #3
    Warhorsei is offline Member
    Join Date
    Jun 2008
    Posts
    3
    Rep Power
    0

    Default

    that would set the layout to the parent JFrame to null not the JPanel...

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    i assumed you've created a class that extends JPanel....

    Nice implementation if you did...

    objectPanel.setLayout(null);
    freedom exists in the world of ideas

  5. #5
    Warhorsei is offline Member
    Join Date
    Jun 2008
    Posts
    3
    Rep Power
    0

    Default

    no change with that, thx for the suggestion. I can gladly make a new class for each panel but I don't see any benefit to doin that in this app

Similar Threads

  1. Help with JButton and layout
    By adlb1300 in forum AWT / Swing
    Replies: 1
    Last Post: 12-25-2007, 08:33 AM
  2. Problems while loading a JPanel to JApplet...
    By Ananth Chellathurai in forum Java Applets
    Replies: 0
    Last Post: 11-24-2007, 10:47 AM
  3. JPanel Problems
    By Riftwalker in forum AWT / Swing
    Replies: 6
    Last Post: 10-15-2007, 11:16 PM
  4. Help with Grid Layout
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:03 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
  •