Frage

I creating a JApplet in java using Netbeans, the problem is the text on JApplet is being cut off, and I've tried to used some different layouts and resizing, but it still turns out the same. enter image description here

Here's the section of my code I used to setup the Applet:

   JPanel jPanel1 = new JPanel();
    jPanel1.setLayout(new FlowLayout());
    jPanel1.add(new JLabel("First Name"));
    jPanel1.add(jtfFname);
    jPanel1.add(new JLabel("Last Name"));
    jPanel1.add(jtfLname);
    jPanel1.add(new JLabel("Phone No."));
    jPanel1.add(jtfphoneNo);
    jPanel1.add(new JLabel("Age 00/00/00"));
    jPanel1.add(jtfage);
    jPanel1.add(new JLabel("Email"));
    jPanel1.add(jtfemail);
    jPanel1.add(new JLabel("Address"));
    jPanel1.add(jtfaddress);
    jPanel1.add(jbtAdd);
        add(jPanel1, BorderLayout.NORTH);
War es hilfreich?

Lösung

A FlowLayout is not a good layout to use for this. It attempts to display components on a single line and will potentially wrap when the width is too small. You can't control this wrapping as the user resizes the frame. Try adding your panel to the CENTER of the Borderlayout and you will see what I mean.

You need to use a more sophisticated layout manager, or nest multiple panels with different layout managers. Check out the Swing tutorial on Using Layout Managers for more information and examples.

For something quick and dirty you can use a GridLayout, but this will make all components the same size. A GridBagLayout is more complicated but you can control the size of individual components better.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top