0

In this code I try to set a size for my label in line 70:

label1.setMinimumSize(new Dimension(150, 100));

But I don't know why the compiler ignores that code so help me to re size my labels in "box layout" and other layouts

This is my code!

package gui1.pkg2;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

/**
 * @author Danial
 */
public class Frame extends JFrame {

    public Frame() {
        setPreferredSize(new Dimension(600, 500));
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBackground(Color.red); //---------------------------------------------------------------------------------->> karnemikone.
        //-------Strat--- ADD sub Classes-------------------
        //-------DownButtons Class----------
        DownButtons dB = new DownButtons();
        add(dB, BorderLayout.SOUTH);
        //-------BlackAndWite Class----------
        BlackAndWite bW = new BlackAndWite();
        add(bW, BorderLayout.WEST);
        //-------RadioButtons Class----------
        radioButtons rB = new radioButtons();
        add(rB, BorderLayout.EAST);
        //-------End----ADD subClasses----------------------
        setVisible(true);
        pack();
        //-----------------------------
    }

    //-------- a class for buttons.--------------
    class DownButtons extends JPanel {

        public DownButtons() {
            setLayout(new FlowLayout());
            JButton save = new JButton("Save");
            save.setBackground(new java.awt.Color(150, 231, 19));
            JButton exit = new JButton("Exit");
            exit.setBackground(new java.awt.Color(150, 231, 19));
            JButton cancel = new JButton("cancel");
            cancel.setBackground(new java.awt.Color(150, 231, 19));
            add(save);
            add(exit);
            add(cancel);
            pack();
        }
    }

    class BlackAndWite extends JPanel {

        public BlackAndWite() {
            setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
            JLabel label1 = new JLabel("              ");
            label1.setOpaque(true);
            label1.setMinimumSize(new Dimension(150, 100));
            label1.setBackground(Color.red);
            add(label1);
        }
    }

    class radioButtons extends JPanel {


        public radioButtons() {


            setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

            class Inner extends JPanel {

                public Inner(String labl, String r1, String r2) {

                    setLayout(new FlowLayout());
                    JLabel label = new JLabel(labl);
                    label.setOpaque(true);
                    label.setBackground(Color.YELLOW);
                    add(label);

                    JRadioButton radio1 = new JRadioButton(r1 + "");
                    JRadioButton radio2 = new JRadioButton(r2);
                    add(radio1);
                    add(radio2);
                }
            }
            Inner in = new Inner(gender, male , Female);
            ///add(in);

        }
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Mr Stone
  • 11
  • 3
  • and i should to say i just new the frame class in my Main class – Mr Stone May 28 '14 at 11:34
  • 1
    Calm down and think about your question -- you must assume that we don't know what you're trying to do, and that therefore, in order to get a question answered, you must explain what you're trying to do. Also, cut down the code you're giving us to just that amount that illustrates what you're trying to do, while still being runnable. As it is, I don't know whether you're trying to set a width or a height, or both, and don't know why you're trying to set a size at all, etc. – arcy May 28 '14 at 11:35
  • *"..the second problem.."* Whoa up there! This is a Q&A site not a help desk. Speaking of which, what is your question? – Andrew Thompson May 28 '14 at 11:36
  • 1
    See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) – Andrew Thompson May 28 '14 at 11:38
  • 2
    and to switch two code lines setVisible(true); and pack();, because pack() should be before visibility – mKorbel May 28 '14 at 11:39
  • but i don't know way the compiler ignore that code so help me to re size my labels in "box layout" and other layouts - BoxLayout required to override all three parameters – mKorbel May 28 '14 at 11:41
  • 1
    The compiler didn't ignore anything, layout managers are allowed to ignore the sizing hints from components as they see fit – MadProgrammer May 28 '14 at 12:08

0 Answers0