Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Need help editing the size of a JButton!?!?

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Need help editing the size of a JButton!?!?

    My two buttons "Calculate" and "Translate" is taking up the entire portion of their respected panel when added. How can I shrink the size of the button so it looks normal?

    Screen Shot 2013-08-24 at 2.16.39 PM.jpg


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Need help editing the size of a JButton!?!?

    What have you tried?
    How is the layout managed? ...with a layout manager or other?

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need help editing the size of a JButton!?!?

     
    //This is where I am creating my mainPanel1 and mainPanel2 layout and borders. 
     
    Border lineBorder = new LineBorder(Color.BLUE, 2);
            mainPanel1 = new JPanel(new GridLayout(4,1));
            mainPanel1.setBorder(BorderFactory.createTitledBorder(lineBorder, "COLOR --> VALUE", 1, 2, null,Color.GREEN));
            mainPanel2 = new JPanel(new GridLayout(3,1,5,5));
            mainPanel2.setBorder(BorderFactory.createTitledBorder(lineBorder, "VALUE --> COLOR", 1, 2, null,Color.GREEN));
     
    //This is where I'm adding my calculate1 button to my mainPanel1 and calculate2 button to my mainPanel2
     
    calculate1 = new javax.swing.JButton();
            calculate1.setText("CALCULATE");
            mainPanel1.add(calculate1);
            calculate1.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent evt){
                    calculate1ActionPerformed(evt);
                }
            });
     
            calculate2 = new javax.swing.JButton();
            calculate2.setText("TRANSLATE");
            p2a.add(calculate2);
            calculate2.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent evt){
                    calculate2ActionPerformed(evt);
                }
            });


    --- Update ---

    I have tried doing a set-dimensions that didn't work. I tried messing with my mainPanel 1 & 2 array size specifying new horizontal and vertical gaps but that didn't work either. I tried doing a set-location I believe it was to left or right or middle and that didn't do anything either.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Need help editing the size of a JButton!?!?

    There are several methods that would set a dimension for a component, (some of which have been depreciated). Can you post a SSCCE that shows where you are setting the size?
    Layout managers (GridLayout) will set the size of each component to or greater than their preferred size, have you set the preferred size?

  5. #5
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Need help editing the size of a JButton!?!?

    Hello.
    You may set the dimensions using setPreferredSize() or setSize() methods.
    You can also set the X and Y location for the buttons.
    Just check the API - JButton (Java Platform SE 7 )
    Let us know if the problem is resolved.

    Syed.

  6. #6
    Junior Member
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need help editing the size of a JButton!?!?

    I was hoping I wouldn't have to do this but I can't get it to work by doing the set dimensions. I'm posting it all below here. I commented above the line where I was trying to set the dimensions of the button "calculate". It's about 1/3 of the way down above all my public void functions. There is some functionality that is not being used so I apologize for any unorganized sections. I'm still in the building stage. That and I'm a newbie.

    import java.awt.*;
    import javax.swing.border.TitledBorder;
    import javax.swing.BorderFactory;
    import java.awt.Color;
    import java.awt.event.ItemEvent;
    import java.lang.Math.*;
    import javax.swing.*;
    //import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.Border;
    import javax.swing.border.LineBorder;
     
     
     
    public class resistortests extends javax.swing.JFrame
    {
     
        int Band1,Band2,Band3,Band4 = 0;
        double tol = 0;
        double temp = 0;
        double val = 0;
     
        Color digit_1, digit_2, digit_3, multiplier, toler, tempe;
        //String multiplier;
     
     
        public javax.swing.ButtonGroup bandTypeButtonGroup;
        public javax.swing.JRadioButton bandFourType;
        public javax.swing.JRadioButton bandFiveType;
        public javax.swing.JRadioButton bandSixType;
        public javax.swing.JButton calculate1;
        public javax.swing.JButton calculate2;
        //public javax.swing.JButton t;
        public javax.swing.JLabel valueLabel;
        public javax.swing.JTextField Value;
        public javax.swing.JLabel ToleranceLabel;
        public javax.swing.JTextField Tolerance;
        public javax.swing.JLabel TemperatureLabel;
        public javax.swing.JTextField Temperature;
        public javax.swing.JComboBox box1;
        public javax.swing.JComboBox box2;
        public javax.swing.JComboBox box3;
        public javax.swing.JComboBox box4;
        public javax.swing.JComboBox box5;
        public javax.swing.JComboBox box6;
     
        public javax.swing.JComboBox d_box1;
        public javax.swing.JComboBox d_box2;
        public javax.swing.JComboBox d_box3;
        public javax.swing.JComboBox d_box4;
        public javax.swing.JComboBox d_box5;
        public javax.swing.JComboBox d_box6;
     
        public javax.swing.JPanel mainPanel1;
        public javax.swing.JPanel mainPanel2;
        public javax.swing.JPanel x1;
        public javax.swing.JPanel x1a;
        public javax.swing.JPanel x2;
        public javax.swing.JPanel resPanel;
        public javax.swing.JPanel resPanel_0;
        public javax.swing.JPanel resPanel_1;
        public javax.swing.JPanel resPanel_2;
        public javax.swing.JPanel resPanel_3;
        public javax.swing.JPanel resPanel_4;
        public javax.swing.JPanel resPanel_5;
        public javax.swing.JPanel resPanel_6;
        public javax.swing.JPanel resPanel_7;
        public javax.swing.JPanel resPanel_8;
        public javax.swing.JPanel resPanel_9;
        public javax.swing.JPanel resPanel_10;
        public javax.swing.JPanel resPanel_11;
        public javax.swing.JPanel resPanel_12;
        public javax.swing.JPanel p1;
        public javax.swing.JPanel p2;
        public javax.swing.JPanel p2a;
        private Border Border;
     
     
        public resistortests()
        {
     
     
            //START OF TRAN
     
     
     
    //public GradientTranslucentWindowDemo() {
            super("GradientTranslucentWindow");
     
            setBackground(new Color(0,0,0,0));
            setSize(new Dimension(800,800));
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            JPanel panel = new JPanel()
            {
                @Override
                protected void paintComponent(Graphics g) {
                    if (g instanceof Graphics2D) {
                        final int R = 70;
                        final int G = 70;
                        final int B = 70;
     
                        Paint p =
                            new GradientPaint(0.f, 0.f, new Color(R, G, B, 0),
                                0.f, getHeight(), new Color(R, G, B, 255), true);
                        Graphics2D g2d = (Graphics2D)g;
                        g2d.setPaint(p);
                        g2d.fillRect(0, 0, getWidth(), getHeight());
                    }
                }
            };
            setContentPane(panel);
            //setLayout(new GridBagLayout());
            //add(new JButton("I am a Button"));
        //}
     
     
     
     
     
    //END OF TRAN
     
     
     
     
     
     
     
     
     
     
     
            initComponents();
        }//END 'PUBLIC RESISTORTESTS()'
     
     
        public void initComponents()
        {
     
            Border lineBorder = new LineBorder(Color.BLUE, 2);
            mainPanel1 = new JPanel(new GridLayout(4,1));
            mainPanel1.setBorder(BorderFactory.createTitledBorder(lineBorder, "COLOR --> VALUE", 1, 2, null,Color.GREEN));
            mainPanel2 = new JPanel(new GridLayout(3,1,5,5));
            mainPanel2.setBorder(BorderFactory.createTitledBorder(lineBorder, "VALUE --> COLOR", 1, 2, null,Color.GREEN));
     
     
            x1 = new JPanel(new GridLayout(1,6,1,1));
            //x1.setBackground(Color.decode("0x66CCFF"));
            //x1.setBorder(new TitledBorder("COLOR SELECTION"));
            x1.setBorder(BorderFactory.createTitledBorder(lineBorder, "COLOR SELECTION", 1, 2, null,Color.GREEN));
     
     
            //x1a = new JPanel(new GridLayout(1,1));
            //x1a.setBackground(Color.decode("0x66CCFF"));
     
            x2 = new JPanel(new GridLayout(3,2,1,1));
            //x2.setBorder(new TitledBorder("RESISTOR DATA"));
            x2.setBorder(BorderFactory.createTitledBorder(lineBorder, "RESISTOR DATA", 1, 2, null,Color.GREEN));
     
            //x2.setBackground(Color.decode("0x66CCFF"));
     
            p1 = new JPanel(new GridLayout(1,3,1,1));
            p1.setBorder(new TitledBorder("BAND TYPE SELECTION"));
            p1.setBorder(BorderFactory.createTitledBorder(lineBorder, "VALUE --> COLOR", 1, 2, null,Color.GREEN));
     
            //p1.setBackground(Color.decode("0x66CCFF"));
     
            p2 = new JPanel(new GridLayout(1,6,1,1));
            p2.setBorder(new TitledBorder("VALUE --> COLOR"));
            p2.setBorder(BorderFactory.createTitledBorder(lineBorder, "VALUE --> COLOR", 1, 2, null,Color.GREEN));
     
            //p2.setBackground(Color.decode("0x66CCFF"));
     
            p2a = new JPanel(new GridLayout(1,1));
            //p2a.setBackground(Color.decode("0x66CCFF"));
     
            resPanel = new JPanel(new GridLayout(1,13));
            resPanel.setBackground(Color.decode("0xFFCC99"));
     
     
            resPanel_0 = new JPanel();
            resPanel_0.setBackground(Color.decode("0xFFCC99"));
     
            resPanel_1 = new JPanel();
            resPanel_1.setBackground(Color.decode("0x000000"));
     
            resPanel_2 = new JPanel();
            resPanel_2.setBackground(Color.decode("0xFFCC99"));
     
            resPanel_3 = new JPanel();
            resPanel_3.setBackground(Color.decode("0x000000"));
     
            resPanel_4 = new JPanel();
            resPanel_4.setBackground(Color.decode("0xFFCC99"));
     
            resPanel_5 = new JPanel();
            resPanel_5.setBackground(Color.decode("0x000000"));
     
            resPanel_6 = new JPanel();
            resPanel_6.setBackground(Color.decode("0xFFCC99"));
     
            resPanel_7 = new JPanel();
            resPanel_7.setBackground(Color.decode("0x000000"));
     
            resPanel_8 = new JPanel();
            resPanel_8.setBackground(Color.decode("0xFFCC99"));
     
            resPanel_9 = new JPanel();
            resPanel_9.setBackground(Color.decode("0xFFFFFF"));
     
            resPanel_10 = new JPanel();
            resPanel_10.setBackground(Color.decode("0xFFCC99"));
     
            resPanel_11 = new JPanel();
            resPanel_11.setBackground(Color.decode("0xFFFFFF"));
     
            resPanel_12 = new JPanel();
            resPanel_12.setBackground(Color.decode("0xFFCC99"));
     
     
            //Sequence of which I added my objects to their panels and the frame
            setLayout(new GridLayout(2,1,5,5));
            add(mainPanel1);
            mainPanel1.add(resPanel);
            resPanel.add(resPanel_0);
            resPanel.add(resPanel_1);
            resPanel.add(resPanel_2);
            resPanel.add(resPanel_3);
            resPanel.add(resPanel_4);
            resPanel.add(resPanel_5);
            resPanel.add(resPanel_6);
            resPanel.add(resPanel_7);
            resPanel.add(resPanel_8);
            resPanel.add(resPanel_9);
            resPanel.add(resPanel_10);
            resPanel.add(resPanel_11);
            resPanel.add(resPanel_12);
            mainPanel1.add(x1);
            //
            mainPanel1.add(x2);
            //mainPanel1.add(x1a);
     
            add(mainPanel2);
            mainPanel2.add(p1);
            mainPanel2.add(p2);
            mainPanel2.add(p2a);
     
            //
     
     
     
            bandTypeButtonGroup = new javax.swing.ButtonGroup();
     
     
            bandFourType = new javax.swing.JRadioButton();
            bandFourType.setText("4 BAND");
            bandFourType.setForeground(Color.ORANGE);
            bandTypeButtonGroup.add(bandFourType);
            p1.add(bandFourType);
            bandFourType.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent evt){
                    bandFourTypeActionPerformed(evt);
                }
            });
     
     
            bandFiveType = new javax.swing.JRadioButton();
            bandFiveType.setText("5 BAND");
            bandFiveType.setForeground(Color.ORANGE);
            bandTypeButtonGroup.add(bandFiveType);
            p1.add(bandFiveType);
            bandFiveType.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent evt){
                   bandFiveTypeActionPerformed(evt); 
                }
            });
     
     
            bandSixType = new javax.swing.JRadioButton();
            bandSixType.setText("6 BAND");
            bandSixType.setForeground(Color.ORANGE);
            bandTypeButtonGroup.add(bandSixType);
            p1.add(bandSixType);
            bandSixType.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent evt){
                    bandSixTypeActionPerformed(evt);
                }
            });
     
     
            valueLabel = new javax.swing.JLabel();
            valueLabel.setText("VALUE");
            valueLabel.setForeground(Color.ORANGE);
            x2.add(valueLabel);
     
     
            Value = new javax.swing.JTextField();
            x2.add(Value);
     
     
            ToleranceLabel = new javax.swing.JLabel();
            ToleranceLabel.setText("TOLERANCE");
            ToleranceLabel.setForeground(Color.ORANGE);
            x2.add(ToleranceLabel);
     
     
            Tolerance = new javax.swing.JTextField();
            x2.add(Tolerance);
     
     
            TemperatureLabel = new javax.swing.JLabel();
            TemperatureLabel.setText("TEMPERATURE");
            TemperatureLabel.setForeground(Color.ORANGE);
            x2.add(TemperatureLabel);
     
     
            Temperature = new javax.swing.JTextField();
            x2.add(Temperature);
     
     
     
     
            //COMBO BOXES FOR BAND COLORS
     
            box1 = new javax.swing.JComboBox();
            box1.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Black", "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Gray", "White"}));
            box1.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    box1ItemStateChanged(evt);
                }
            });
            x1.add(box1);
            //
     
            box2 = new javax.swing.JComboBox();
            box2.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Black", "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Gray", "White"}));
            box2.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    box2ItemStateChanged(evt);
                }
            });
            x1.add(box2);
            //
     
            box3 = new javax.swing.JComboBox();
            box3.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Black", "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Gray", "White"}));
            box3.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    box3ItemStateChanged(evt);
                }
            });
            x1.add(box3);
            //
     
            box4 = new javax.swing.JComboBox();
            box4.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Black", "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Gray", "White"}));
            box4.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    box4ItemStateChanged(evt);
                }
            });
            x1.add(box4);
            //
     
            box5 = new javax.swing.JComboBox();
            box5.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Brown", "Red", "Green", "Blue", "Violet", "Gray", "Gold", "Silver", "None"}));
            box5.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    box5ItemStateChanged(evt);
                }
            });
            x1.add(box5);
            //
     
            box6 = new javax.swing.JComboBox();
            box6.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Brown", "Red", "Orange", "Yellow"}));
            box6.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    box6ItemStateChanged(evt);
                }
            });
            x1.add(box6);
            //
     
            //COMBO BOXES FOR VALUE --> COLOR
     
            d_box1 = new javax.swing.JComboBox();
            d_box1.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}));
            d_box1.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    d_box1ItemStateChanged(evt);
     
                }
            });
            p2.add(d_box1);
            //
     
            d_box2 = new javax.swing.JComboBox();
            d_box2.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}));
            d_box2.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    d_box2ItemStateChanged(evt);
     
                }
            });
            p2.add(d_box2);
            //
     
            d_box3 = new javax.swing.JComboBox();
            d_box3.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}));
            d_box3.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    d_box3ItemStateChanged(evt);
     
                }
            });
            p2.add(d_box3);
            //
     
            d_box4 = new javax.swing.JComboBox();
            d_box4.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"x10" + "\u2070", "x10" + "\u00B9", "x10" + "\u00B2", "x10" + "\u00B3", "x10" + "\u2074", "x10" + "\u2075", "x10" + "\u2076", "x10" + "\u2077", "x10" + "\u2078", "x10" + "\u2079"}));
            d_box4.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    d_box4ItemStateChanged(evt);
     
                }
            });
            p2.add(d_box4);
            //
     
            d_box5 = new javax.swing.JComboBox();
            d_box5.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"\u00B1" + "1%", "\u00B1" + "2%", "\u00B1" + "0.5%", "\u00B1" + "0.25%", "\u00B1" + "0.1%", "\u00B1" + "0.05%", "\u00B1" + "5%", "\u00B1" + "10%", "\u00B1" + "20%"}));
            d_box5.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    d_box5ItemStateChanged(evt);
     
                }
            });
            p2.add(d_box5);
            //
     
            d_box6 = new javax.swing.JComboBox();
            d_box6.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"100 ppm/K", "50 ppm/k", "15 ppm/k", "25 ppm/k"}));
            d_box6.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt){
                    d_box6ItemStateChanged(evt);
     
                }
            });
            p2.add(d_box6);
            //
     
     
            calculate1 = new javax.swing.JButton();
            calculate1.setText("CALCULATE");
     
    //This is the part that is not working 
            calculate1.setPreferredSize(1,2);
            mainPanel1.add(calculate1);
            calculate1.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent evt){
                    calculate1ActionPerformed(evt);
                }
            });
     
            calculate2 = new javax.swing.JButton();
            calculate2.setText("TRANSLATE");
            p2a.add(calculate2);
            calculate2.addActionListener(new java.awt.event.ActionListener(){
                public void actionPerformed(java.awt.event.ActionEvent evt){
                    calculate2ActionPerformed(evt);
                }
            });
     
     
        }//END "PUBLIC VOID INITCOMPONENTS
     
     
     
     
        public void box1ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "Black")
            {
                resPanel_1.setBackground(Color.BLACK);
                Band1 = 0;  
            }
     
            else if (evt.getItem() == "Brown")
            {
                resPanel_1.setBackground(Color.decode("0x996633"));
                Band1 = 1;
            }
     
            else if (evt.getItem() == "Red")
            {
                resPanel_1.setBackground(Color.RED);
                Band1 = 2;
            }
     
            else if (evt.getItem() == "Orange")
            {
                resPanel_1.setBackground(Color.decode("0xFF9900"));
                Band1 = 3;  
            }
     
            else if (evt.getItem() == "Yellow")
            {
                resPanel_1.setBackground(Color.YELLOW);
                Band1 = 4;  
            }
     
            else if (evt.getItem() == "Green")
            {
                resPanel_1.setBackground(Color.GREEN);
                Band1 = 5;  
            }
     
            else if (evt.getItem() == "Blue")
            {
                resPanel_1.setBackground(Color.BLUE);
                Band1 = 6;  
            }
     
            else if (evt.getItem() == "Violet")
            {
                resPanel_1.setBackground(Color.decode("0xCC00FF"));
                Band1 = 7;  
            }
     
            else if (evt.getItem() == "Gray")
            {
                resPanel_1.setBackground(Color.GRAY);
                Band1 = 8;  
            }
     
            else if (evt.getItem() == "White")
            {
                resPanel_1.setBackground(Color.WHITE);
                Band1 = 9;  
            }
     
        }//END BOX1 RESPANEL_1
     
        public void box2ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "Black")
            {
                resPanel_3.setBackground(Color.BLACK);
                Band2 = 0;  
            }
     
            else if (evt.getItem() == "Brown")
            {
                resPanel_3.setBackground(Color.decode("0x996633"));
                Band2 = 1;
            }
     
            else if (evt.getItem() == "Red")
            {
                resPanel_3.setBackground(Color.RED);
                Band2 = 2;
            }
     
            else if (evt.getItem() == "Orange")
            {
                resPanel_3.setBackground(Color.decode("0xFF9900"));
                Band2 = 3;  
            }
     
            else if (evt.getItem() == "Yellow")
            {
                resPanel_3.setBackground(Color.YELLOW);
                Band2 = 4;  
            }
     
            else if (evt.getItem() == "Green")
            {
                resPanel_3.setBackground(Color.GREEN);
                Band2 = 5;  
            }
     
            else if (evt.getItem() == "Blue")
            {
                resPanel_3.setBackground(Color.BLUE);
                Band2 = 6;  
            }
     
            else if (evt.getItem() == "Violet")
            {
                resPanel_3.setBackground(Color.decode("0xCC00FF"));
                Band2 = 7;  
            }
     
            else if (evt.getItem() == "Gray")
            {
                resPanel_3.setBackground(Color.GRAY);
                Band2 = 8;  
            }
     
            else if (evt.getItem() == "White")
            {
                resPanel_3.setBackground(Color.WHITE);
                Band2 = 9;  
            }
     
        }//END BOX2 RESPANEL 3
     
        public void box3ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "Black")
            {
                resPanel_5.setBackground(Color.BLACK);
                Band3 = 0;  
            }
     
            else if (evt.getItem() == "Brown")
            {
                resPanel_5.setBackground(Color.decode("0x996633"));
                Band3 = 1;
            }
     
            else if (evt.getItem() == "Red")
            {
                resPanel_5.setBackground(Color.RED);
                Band3 = 2;
            }
     
            else if (evt.getItem() == "Orange")
            {
                resPanel_5.setBackground(Color.decode("0xFF9900"));
                Band3 = 3;  
            }
     
            else if (evt.getItem() == "Yellow")
            {
                resPanel_5.setBackground(Color.YELLOW);
                Band3 = 4;  
            }
     
            else if (evt.getItem() == "Green")
            {
                resPanel_5.setBackground(Color.GREEN);
                Band3 = 5;  
            }
     
            else if (evt.getItem() == "Blue")
            {
                resPanel_5.setBackground(Color.BLUE);
                Band3 = 6;  
            }
     
            else if (evt.getItem() == "Violet")
            {
                resPanel_5.setBackground(Color.decode("0xCC00FF"));
                Band3 = 7;  
            }
     
            else if (evt.getItem() == "Gray")
            {
                resPanel_5.setBackground(Color.GRAY);
                Band3 = 8;  
            }
     
            else if (evt.getItem() == "White")
            {
                resPanel_5.setBackground(Color.WHITE);
                Band3 = 9;  
            }
     
        }//END BOX3 RESPANEL_5
     
        public void box4ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "Black")
            {
                resPanel_7.setBackground(Color.black);
                Band4 = 0;
            }
            else if (evt.getItem() == "Brown")
            {
                resPanel_7.setBackground(Color.decode("0x996633"));
                Band4 = 1;
            }
            else if (evt.getItem() == "Red")
            {
                resPanel_7.setBackground(Color.RED);
                Band4 = 2;
            }
            else if (evt.getItem() == "Orange")
            {
                resPanel_7.setBackground(Color.decode("0xFF9900"));
                Band4 = 3;
            }
            else if (evt.getItem() == "Yellow")
            {
                resPanel_7.setBackground(Color.YELLOW);
                Band4 = 4;
            }
            else if (evt.getItem() == "Green")
            {
                resPanel_7.setBackground(Color.GREEN);
                Band4 = 5;
            }
            else if (evt.getItem() == "Blue")
            {
                resPanel_7.setBackground(Color.BLUE);
                Band4 = 6;
            }
            else if (evt.getItem() == "Violet")
            {
                resPanel_7.setBackground(Color.decode("0xCC00FF"));
                Band4 = 7;
            }
            else if (evt.getItem() == "Gray")
            {
                resPanel_7.setBackground(Color.GRAY);
                Band4 = 8;
            }
            else if (evt.getItem() == "White")
            {
                resPanel_7.setBackground(Color.WHITE);
                Band4 = 9;
            }
     
        }//END BOX4 RESPANEL_7
     
        public void box5ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "Brown")
            {
                resPanel_9.setBackground(Color.decode("0x996633"));
                tol = 1.0;
            }
            else if (evt.getItem() == "Red")
            {
                resPanel_9.setBackground(Color.RED);
                tol = 2.0;
            }
            else if (evt.getItem() == "Green")
            {
                resPanel_9.setBackground(Color.GREEN);
                tol = 0.5;
            }
            else if (evt.getItem() == "Blue")
            {
                resPanel_9.setBackground(Color.BLUE);
                tol = 0.25;
            }
            else if (evt.getItem() == "Violet")
            {
                resPanel_9.setBackground(Color.decode("0xCC00FF"));
                tol = 0.10;
            }
            else if (evt.getItem() == "Gray")
            {
                resPanel_9.setBackground(Color.GRAY);
                tol = 0.05;
            }
            else if (evt.getItem() == "Gold")
            {
                resPanel_9.setBackground(Color.decode("0xCC9900"));
                tol = 5.0;
            }
            else if (evt.getItem() == "Silver")
            {
                resPanel_9.setBackground(Color.decode("0xE8E8E8"));
                tol = 10.0;
            }
            else if (evt.getItem() == "None")
            {
                resPanel_9.setBackground(Color.WHITE);
                tol = 1.0;
            }
     
        }//END BOX5 RESPANEL_9
     
        public void box6ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "Brown")
            {
                resPanel_11.setBackground(Color.decode("0x996633"));
                temp = 100.00;
            }
            else if (evt.getItem() == "Red")
            {
                resPanel_11.setBackground(Color.RED);
                temp = 50.00;
            }
            else if (evt.getItem() == "Orange")
            {
                resPanel_11.setBackground(Color.decode("0xFF9900"));
                temp = 15.00;
            }
            else if (evt.getItem() == "Yellow")
            {
                resPanel_11.setBackground(Color.YELLOW);
                temp = 25.00;
            }
     
        }//END BOX5 RESPANEL_11
     
        public void d_box1ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "Black")
            {
                digit_1 = Color.BLACK;
            }
     
            else if (evt.getItem() == "Brown")
            {
                digit_1 = Color.decode("0x996633");
            }
     
            else if (evt.getItem() == "Red")
            {
                digit_1 = Color.RED;
            }
     
            else if (evt.getItem() == "Orange")
            {
                digit_1 = Color.decode("0xFF9900");
            }
     
            else if (evt.getItem() == "Yellow")
            {
                digit_1 = Color.YELLOW;
            }
     
            else if (evt.getItem() == "Green")
            {
                digit_1 = Color.GREEN;
            }
     
            else if (evt.getItem() == "Blue")
            {
                digit_1 = Color.BLUE;
            }
     
            else if (evt.getItem() == "Violet")
            {
                digit_1 = Color.decode("0xCC00FF");
            }
     
            else if (evt.getItem() == "Gray")
            {
                digit_1 = Color.GRAY;
            }
     
            else if (evt.getItem() == "White")
            {
                digit_1 = Color.WHITE;
            }
     
        }//END D_BOX1 DIGIT 1
     
        public void d_box2ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "Black")
            {
                digit_2 = Color.BLACK;
            }
     
            else if (evt.getItem() == "Brown")
            {
                digit_2 = Color.decode("0x996633");
            }
     
            else if (evt.getItem() == "Red")
            {
                digit_2 = Color.RED;
            }
     
            else if (evt.getItem() == "Orange")
            {
                digit_2 = Color.decode("0xFF9900");
            }
     
            else if (evt.getItem() == "Yellow")
            {
                digit_2 = Color.YELLOW;
            }
     
            else if (evt.getItem() == "Green")
            {
                digit_2 = Color.GREEN;
            }
     
            else if (evt.getItem() == "Blue")
            {
                digit_2 = Color.BLUE;
            }
     
            else if (evt.getItem() == "Violet")
            {
                digit_2 = Color.decode("0xCC00FF");
            }
     
            else if (evt.getItem() == "Gray")
            {
                digit_2 = Color.GRAY;
            }
     
            else if (evt.getItem() == "White")
            {
                digit_2 = Color.WHITE;
            }
     
        }//END D_BOX2 DIGIT 2
     
        public void d_box3ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "Black")
            {
                digit_3 = Color.BLACK;
            }
     
            else if (evt.getItem() == "Brown")
            {
                digit_3 = Color.decode("0x996633");
            }
     
            else if (evt.getItem() == "Red")
            {
                digit_3 = Color.RED;
            }
     
            else if (evt.getItem() == "Orange")
            {
                digit_3 = Color.decode("FF9900");
            }
     
            else if (evt.getItem() == "Yellow")
            {
                digit_3 = Color.YELLOW;
            }
     
            else if (evt.getItem() == "Green")
            {
                digit_3 = Color.GREEN;
            }
     
            else if (evt.getItem() == "Blue")
            {
                digit_3 = Color.BLUE;
            }
     
            else if (evt.getItem() == "Violet")
            {
                digit_3 = Color.decode("0xCC00FF");
            }
     
            else if (evt.getItem() == "Gray")
            {
                digit_3 = Color.GRAY;
            }
     
            else if (evt.getItem() == "White")
            {
                digit_3 = Color.WHITE;
            }
     
        }//END D_BOX3 DIGIT 3
     
        public void d_box4ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "x10" + "\u2070")
            {
                multiplier = Color.BLACK;
            }
     
            else if (evt.getItem() == "x10" + "\u00B9")
            {
                multiplier = Color.decode("0x996633");
            }
     
            else if (evt.getItem() == "x10" + "\u00B2")
            {
                multiplier = Color.RED;
            }
     
            else if (evt.getItem() == "x10" + "\u00B3")
            {
                multiplier = Color.decode("0xFF9900");
            }
     
            else if (evt.getItem() == "x10" + "\u2074")
            {
                multiplier = Color.YELLOW;
            }
     
            else if (evt.getItem() == "x10" + "\u2075")
            {
                multiplier = Color.GREEN;
            }
     
            else if (evt.getItem() == "x10" + "\u2076")
            {
                multiplier = Color.BLUE;
            }
     
            else if (evt.getItem() == "x10" + "\u2077")
            {
                multiplier = Color.decode("0xCC00FF");
            }
     
            else if (evt.getItem() == "x10" + "\u2078")
            {
                multiplier = Color.GRAY;
            }
     
            else if (evt.getItem() == "x10" + "\u2079")
            {
                multiplier = Color.WHITE;
            }
     
        }//END D_BOX4 MULTIPLIER
     
        public void d_box5ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "\u00B1" + "1%")
            {
                toler = Color.decode("0x996633");
            }
     
            else if (evt.getItem() == "\u00B1" + "2%")
            {
                toler = Color.RED;
            }
     
            else if (evt.getItem() == "\u00B1" + "0.5%")
            {
                toler = Color.GREEN;
            }
     
            else if (evt.getItem() == "\u00B1" + "0.25%")
            {
                toler = Color.BLUE;
            }
     
            else if (evt.getItem() == "\u00B1" + "0.1%")
            {
                toler = Color.decode("0xCC00FF");
            }
     
            else if (evt.getItem() == "\u00B1" + "0.05%")
            {
                toler = Color.GRAY;
            }
     
            else if (evt.getItem() == "\u00B1" + "5%")
            {
                toler = Color.decode("0xCC9900");
            }
     
            else if (evt.getItem() == "\u00B1" + "10%")
            {
                toler = Color.decode("0xE8E8E8");
            }
     
            else if (evt.getItem() == "\u00B1" + "20%")
            {
                toler = Color.PINK;
            }
     
     
        }//END D_BOX5 TOLE
     
        public void d_box6ItemStateChanged(java.awt.event.ItemEvent evt)
        {
            if (evt.getItem() == "100 ppm/K")
            {
                tempe = Color.decode("0x996633");
            }
     
            else if (evt.getItem() == "50 ppm/k")
            {
                tempe = Color.RED;
            }
     
            else if (evt.getItem() == "15 ppm/k")
            {
                tempe = Color.decode("0xFF9900");
            }
     
            else if (evt.getItem() == "25 ppm/k")
            {
                tempe = Color.YELLOW;
            }
     
        }//END D_BOX6 TEMPE
     
        public void bandFourTypeActionPerformed(java.awt.event.ActionEvent evt){
            resPanel_1.setVisible(false);
            box1.setVisible(false);
     
            resPanel_3.setVisible(true);
            box2.setVisible(true);
     
            resPanel_5.setVisible(true);
            box3.setVisible(true);
     
            resPanel_7.setVisible(true);
            box4.setVisible(true);
     
            resPanel_9.setVisible(true);
            box5.setVisible(true);
     
            resPanel_11.setVisible(false);
            box6.setVisible(false);
     
            d_box1.setVisible(false);
     
            d_box2.setVisible(true);
     
            d_box3.setVisible(true);
     
            d_box4.setVisible(true);
     
            d_box5.setVisible(true);
     
            d_box6.setVisible(false);
     
        }//END OF RADIOBUTTON 4BAND
     
     
     
     
    public void bandFiveTypeActionPerformed(java.awt.event.ActionEvent evt){
     
            resPanel_1.setVisible(true);
            box1.setVisible(true);
     
            resPanel_3.setVisible(true);
            box2.setVisible(true);
     
            resPanel_5.setVisible(true);
            box3.setVisible(true);
     
            resPanel_7.setVisible(true);
            box4.setVisible(true);
     
            resPanel_9.setVisible(true);
            box5.setVisible(true);
     
            resPanel_11.setVisible(false);
            box6.setVisible(false);
     
            d_box1.setVisible(true);
     
            d_box2.setVisible(true);
     
            d_box3.setVisible(true);
     
            d_box4.setVisible(true);
     
            d_box5.setVisible(true);
     
            d_box6.setVisible(false);
    }//END OF RADIOBUTTON 5BAND
     
    public void bandSixTypeActionPerformed(java.awt.event.ActionEvent evt){
     
            resPanel_1.setVisible(true);
            box1.setVisible(true);
     
            resPanel_3.setVisible(true);
            box2.setVisible(true);
     
            resPanel_5.setVisible(true);
            box3.setVisible(true);
     
            resPanel_7.setVisible(true);
            box4.setVisible(true);
     
            resPanel_9.setVisible(true);
            box5.setVisible(true);
     
            resPanel_11.setVisible(true);
            box6.setVisible(true);
     
            d_box1.setVisible(true);
     
            d_box2.setVisible(true);
     
            d_box3.setVisible(true);
     
            d_box4.setVisible(true);
     
            d_box5.setVisible(true);
     
            d_box6.setVisible(true);
     
    }//END OF RADIOBUTTON 6BAND
     
    public void calculate1ActionPerformed(java.awt.event.ActionEvent evt){
     
        if (bandFourType.isSelected())
        {
            val = ((Band2 * 10) + Band3) * Math.pow(10.0,Band4);
            Value.setText(Double.toString(val));
            Tolerance.setText("\u00B1" + Double.toString(tol) + "\u0025");
        }
     
        else if (bandFiveType.isSelected())
        {
            val = ((Band1 * 100)+(Band2 * 10) + Band3) * Math.pow(10.0,Band4);
            Value.setText(Double.toString(val));
            Tolerance.setText("\u00B1" + Double.toString(tol) + "\u0025");
        }
     
        else if (bandSixType.isSelected())
        {
            val = ((Band1 * 100) + ((Band2 * 10) + Band3)) * Math.pow(10.0, Band4);
            Value.setText(Double.toString(val) + " \u2126");
            Tolerance.setText("\u00B1" + Double.toString(tol) + "\u0025");
            Temperature.setText(Double.toString(temp) + " PPM/" + "\u2103");
        }
     
     
    }
     
    public void calculate2ActionPerformed(java.awt.event.ActionEvent evt){
        if (bandFourType.isSelected())
        {
     
     
     
            resPanel_3.setBackground(digit_2);
            resPanel_5.setBackground(digit_3);
            resPanel_7.setBackground(multiplier);
            resPanel_9.setBackground(toler);
        }
     
        else if (bandFiveType.isSelected())
        {
            resPanel_1.setBackground(digit_1);
            resPanel_3.setBackground(digit_2);
            resPanel_5.setBackground(digit_3);
            resPanel_7.setBackground(multiplier);
            resPanel_9.setBackground(toler);
        }
     
        else if (bandSixType.isSelected())
        {
            resPanel_1.setBackground(digit_1);
            resPanel_3.setBackground(digit_2);
            resPanel_5.setBackground(digit_3);
            resPanel_7.setBackground(multiplier);
            resPanel_9.setBackground(toler);
            resPanel_11.setBackground(tempe);
        }
     
    }
     
     
     
        public static void main(String args[])
        {
     
     
            SwingUtilities.invokeLater(new Runnable()
            {
                @Override
                public void run()
                {
                    resistortests gtw = new
                        resistortests();
                    // Display the window.
                    gtw.setVisible(true);
                }
            });
     
     
     
           /* JFrame resFrame = new resistortests();
            resFrame.setSize(500, 800);
            resFrame.setLocationRelativeTo(null);
            resFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            resFrame.setVisible(true);*/
     
        }//END 'PUBLIC STATIC VOID MAIN(STRING ARGS[])'
     
    }//END 'PUBLIC CLASS RESISTORTEST EXTENDS ....'

  7. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Need help editing the size of a JButton!?!?

    //This is the part that is not working
    calculate1.setPreferredSize(1,2);

    setPreferredSize() takes a Dimension as a parameter

Similar Threads

  1. Jpanel preffered size exceed the nactual screen size
    By manish.ctae@gmail.com in forum AWT / Java Swing
    Replies: 2
    Last Post: October 31st, 2012, 01:29 AM
  2. editing array
    By silverspoon34 in forum Object Oriented Programming
    Replies: 1
    Last Post: April 15th, 2011, 01:40 AM
  3. Editing a date
    By waterjames in forum Java Theory & Questions
    Replies: 0
    Last Post: November 27th, 2010, 01:00 PM
  4. Limit File Size or Request Size
    By tarek.mostafa in forum Java Servlet
    Replies: 3
    Last Post: June 12th, 2010, 04:28 PM
  5. Limit File Size or Request Size
    By tarek.mostafa in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: June 11th, 2010, 07:21 AM

Tags for this Thread