Results 1 to 2 of 2
  1. #1
    such orb is offline Member
    Join Date
    Mar 2012
    Posts
    24
    Rep Power
    0

    Default jlabels don't size by using setbounds within a null layout

    Hi, i am quite new to java.

    i can't set a jlabels size while using a null layout. afaik, everything else is working just fine... problem is that setbounds won't change the jlabel's size. i have tried everything i can think of, but, nothing is working.


    import java.awt.Color;
    import java.awt.Font;

    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;

    public class crash extends JFrame {

    {

    JFrame frame = new JFrame("test");

    frame.setBounds(0, 0, 1920, 1080);
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setLayout(null);
    frame.pack();
    frame.setVisible(true);

    {
    JPanel panel = new JPanel(null);
    panel.setBackground(Color.black);
    panel.setLayout(null);

    panel.setBounds(0, 0, 1000, 800);

    frame.add(panel);
    panel.setVisible(true);

    {
    setLayout(null);
    JLabel jl = new JLabel("test text");

    jl.setFont(new Font("Arial", Font.PLAIN, 20));

    jl.setBounds(200, 200, 400, 400);
    jl.setForeground(Color.blue);

    panel.add(jl);
    jl.setVisible(true);

    }
    }
    }
    }

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

    Default Re: jlabels don't size by using setbounds within a null layout

    1) Look around the FAQs section of the site and learn how to post code so it retains its formatting.
    2) Don't use a null layout and setBounds(...), use an appropriate layout manager: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    3) Follow coding conventions. Class names start with an uppercase letter.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 5
    Last Post: 02-28-2012, 01:49 PM
  2. Size of serialized object with null values
    By jamesd128 in forum New To Java
    Replies: 1
    Last Post: 10-22-2010, 06:43 PM
  3. add scrollbar in JFrame with null Layout
    By sajib_bd in forum AWT / Swing
    Replies: 1
    Last Post: 10-12-2010, 09:53 AM
  4. Replies: 4
    Last Post: 08-05-2010, 08:08 AM
  5. set button size in case of layout managers
    By silversurfer2in in forum AWT / Swing
    Replies: 3
    Last Post: 06-22-2010, 10:23 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
  •