Hi,

I'm using a JTextArea in a JApplet, and having difficulty trying to align the JTextArea on the x, y axis... I've tries setBounds, setAlignmentX & setLocation... Neither seem to work. Plz help!

This is what I have:

public class Testing () {  
  JTextArea TxtArea;
  Container Panel;
  LayoutManager Layout;

  public Testing() extends JApplet {    
    TxtArea = new JTextArea ();
    Layout = new FlowLayout ();
    Panel = getContentPane ();

    TxtArea.setBounds(240, 48, 402, 184);
    TxtArea.setEditable (false);
    TxtArea.setBackground (Color.white);
    TxtArea.setLineWrap (true);
    Panel.setLayout (Layout);
    Panel.add (TxtArea);
  }
  
  public void paint(Graphics g) {
    TxtArea.setText("HELLO!! :...><><>>>>>><");
  }

Hi,

Didn't quite help too much... Can someone please just make it aligned on the 1/3 of the page (a bit above center) of the JApplet that is 900x600, Please? I'll Rep++


- Thank you!

Can someone please do that for me? As I said, I'll Rep++ & mark as solved :)

- Thanks!

I am not judge you but I can think that you have no idea to write java code or you are misleading us.
After all, your code is completely incorrect.

Here is the corrected code.
Testing.java

import java.awt.*;
import java.applet.*;
import javax.swing.*;

public class Testing extends JApplet {  
  JTextArea TxtArea;
  Container panel;
  LayoutManager Layout;

  public Testing(){    
    TxtArea = new JTextArea ();
    Layout = new BorderLayout ();
    panel = getContentPane ();
    
    TxtArea.setEditable (false);
    TxtArea.setBackground (Color.white);
    TxtArea.setLineWrap (true);
    panel.setLayout (Layout);
    panel.add (TxtArea);
  }
  
  public void paint(Graphics g) {
    TxtArea.setText("HELLO!! :...><><>>>>>><");
  }
}

Hey,

I know how to add Layout = new BorderLayout (); I meant, set the parameters that make it align on the JApplet..? Thats what I'm having trouble with...

Thanks!

Hey,

I know how to add Layout = new BorderLayout (); I meant, set the parameters that make it align on the JApplet..? Thats what I'm having trouble with...

Thanks!

It is your code....

public class Testing () {  
   ......
  public Testing() extends JApplet {    
       ....
   }
  
  ....

NVM, I've solved it by setting the layout to null and then using setBounds.

This article has been dead for over six months. Start a new discussion instead.