Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7688585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:57:19+00:00 2026-05-31T19:57:19+00:00

I am just starting with applets so I am not to good. I recently

  • 0

I am just starting with applets so I am not to good. I recently tried using this code:

public class AppletTest extends JApplet{    
  public void init(){
    try{
        SwingUtilities.invokeAndWait(new Runnable(){public void run(){
        setSize(500,500);
        JLabel lbl = new JLabel("Hello World");
        add(lbl);
        JTextPane pane = new JTextPane();
        pane.setSize(200, 200);
        add(pane);
        }});
    }catch(Exception e){
        System.err.println("Error Occurred");
    }
  }
}

What I intended it to do was make a 500 by 500 applet with a text pane that is 200 by 200. However, when I ran the program, the text pane flashed for a moment in the correct size then proceeded to fill up the applet and cover anything else I put on in the applet. If I expanded the applet (manipulated it by dragging the corner) the text pane would grow as well. I tried this and got the same results with a JButton and a JPasswordField. Is there something I am missing? I tried setBounds(int i, int j, int k, int l) But I got the same results. Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:57:21+00:00Added an answer on May 31, 2026 at 7:57 pm

    You need to change two things:

    1. Explicitly set a LayoutManager (FlowLayout is simple and works fine here)

    2. Call setPreferredSize() instead of setSize() for your JTextPanel

    Here’s the modified code:

    import java.awt.Dimension;
    import java.awt.FlowLayout;
    
    import javax.swing.JApplet;
    import javax.swing.JLabel;
    import javax.swing.JTextPane;
    import javax.swing.SwingUtilities;
    
    public class AppletTest extends JApplet{    
      public void init(){
        try{
            SwingUtilities.invokeAndWait(new Runnable(){public void run(){
            setSize(500,500);
    
            // explicitly set a layout manager
            setLayout( new FlowLayout( ) );
    
            JLabel lbl = new JLabel("Hello World");
            add(lbl);
            JTextPane pane = new JTextPane();
    
            // use setPreferredSize, not setSize
            pane.setPreferredSize( new Dimension( 200, 200 ) );
    
            add(pane);
            }});
        }catch(Exception e){
            System.err.println("Error Occurred");
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just starting up with iPhone development. I'm not sure why this code works. I've
Just starting my way with Roboguice for android. Tried implementing this simple context injection
I just starting using VS2005 and I wish to have code highlighting in C/C++.
im just starting to learn about sockets and i have been given this code,
Just starting learning about ajax requests using jQuery. I've tried looking at other posts
Just starting to learn ASP.NET (C#) and I am using Visual Studio 2008. I
Just starting out, this should be a simple one but I haven't been able
Just starting out with an iPhone application using xcode 4.2. I understand that it
Just starting out with C#, so this may be overly simple that I keep
Just starting using the Firebug console. I have a test script which I'll post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.