#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    2

    JLabel text on second frame


    Why is my instructions JLabel not displaying properly? The text either stays horizontal or turns into a narrow column. Can someone help me solve this issue please?

    Code:
    package pkgCarInsuranceCalc;
    
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class Instructions extends JFrame{
        
    JLabel lblInstructions = new JLabel();
    
        public Instructions(){
            super("Instructions"); // frame title
            
            // adding and setting panel
            JPanel panel = new JPanel(new GridBagLayout());
            panel.setBackground(Color.WHITE); // panel background colour
            add(panel);
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(10,10,10,10);
            
            // label for instructions
            lblInstructions.setText("<html><span style='font-size:15'>" +
                            "Want to know the average premium costs from around " +
                            "the country?<br>Then this calculator can help.<br> " +
                            "Just select your area, age, sex and claims from the " +
                            "menus, press 'Calculate', and you'll be presented " +
                            "with the current average premium.<br>The prices " +
                            "calculated should be treated as a rough guide only. " +
                            "<br>There are plently of other factors which are " +
                            "likely to affect the premium you pay - such as make " +
                            "and model of car, and convictions history and so on.");
            gbc.gridx = 0;
            gbc.gridy = 10;
            panel.add(lblInstructions, gbc);
            
        }
        
    } // end of Instructions class
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,719
    Rep Power
    348
    How do you execute the code for testing? I don't see a main() method.
    Please add a main() method.

IMN logo majestic logo threadwatch logo seochat tools logo