[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 727
  • Last Modified:

Removing window border from around the TextArea AWT object

Is there a way to remove the border from the TextArea object when the scrollbars are not going to be used?  I basically want to see the text itself on the screen.  If you can not remove the border, then is there another approach I should take?  I tried using DisplayString, but I have to separate each line of text into separate string objects to display them on separate lines.  This is not a good solution for my application.  Any other ideas?

TIA
Mark
0
mbonney
Asked:
mbonney
  • 4
  • 2
  • 2
1 Solution
 
sankars98Commented:

 If you want to remove border from scrollpane , you can use empty border.

        scrollpane.setBorder( BorderFactory.createEmptyBorder());
0
 
mbonneyAuthor Commented:
sankars98, I tried your suggestion without success.  I guess I need to meantion that I'm using JDK 1.1.8 and that is why I'm using AWT vs Swing.  I could not find the setBorder method for scrollpane and as I looked I could not see the inheritance relationship between scrollpane and TextArea.  If you're thinking I should scrollpane to show the text, then please elaborate further.

Thanks
Mark
0
 
sankars98Commented:

 I am sorry .. I thought you are using
 Swing Components. Borders can be set only to the swing components. I dont know whether we can change the border of AWT components( Native ). Sorry again..

Sankar S.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ya87Commented:
i am not sure, if i understood your problem...
you only want do display a String in multiple lines, and you don´t
need the interaction possibilities of a textarea (e.g. changing
the text interactively)?
if so, you only need o subclass the label-class to make it "multi-line"-capable. if i am right and you need a copy´n paste
example, place a comment, i´ll send it.

ya87
0
 
mbonneyAuthor Commented:
ya87,
Yes.  I want to display multiple lines of text that is not editable, but I need to be able to determine length and width of the text area for placement.  Textarea is nice because it automatically wraps therfore I do not have to calculate the line length to determine when/where to start the new line of text.  I will also need to be able to handle mouses clicks within the text area.  So, clickable text that autowraps and does not have a border around it.

Thanks,
Mark
0
 
ya87Commented:
okay, here´s your code. just copy, paste and have fun - it should work.
don´t hesitate and report any bugs.



import java.awt.*;
import java.util.*;

public class Multilabel extends Label{

private Dimension D=null;
private FontMetrics fm;
private int line_height,line_ascent;
private int maxwidth;
private Vector textlines;
private String text;
private int leftinset=2;
private int rightinset=2;

public Multilabel(String text,int maxwidth){
 super ();
 this.text=text;
 this.maxwidth=maxwidth-leftinset-rightinset;
}


public void addNotify(){
 fm = this.getToolkit().getFontMetrics(this.getFont());
 line_height = fm.getHeight();
 line_ascent = fm.getAscent();
 textlines=new Vector();
 split (text,textlines,maxwidth);
 D=new Dimension (maxwidth,line_height * textlines.size());
 super.addNotify();
}

public void split (String text, Vector v, int maxw){
// splits the String given in "text" into multiple Strings, arranged in a Vector.
// every line is not wider than "maxw" pixel.
// split wraps the text word for word, but if a single word needs more space than
// maxw allows, the line (this word) will be clipped, so take care of very long words!

 StringTokenizer st = new StringTokenizer(text," ");
 Vector words = new Vector();
 while (st.hasMoreElements()) words.addElement(st.nextElement());

 if (fm.stringWidth(text)<=maxw)
    { // no split necessary
     v.addElement(text);
     return;
    }

 if (words.size()==1)
    { // no split possible, output will be clipped
     v.addElement(text);
     return;
    }

 // now comes the tricky part :-)

 int z=0;

 StringBuffer newLine = new StringBuffer(words.elementAt(0).toString());

 for (z=1;z<words.size();z++)
   if (fm.stringWidth(newLine.toString()+" "+words.elementAt(z).toString())<maxw) newLine.append(" "+words.elementAt(z).toString());
   else
      {
       v.addElement (newLine.toString());
       newLine = new StringBuffer(words.elementAt(z).toString());
      }
  v.addElement (newLine.toString());
}


public void paint (Graphics g){
 for (int i=0; i<textlines.size(); i++)
     g.drawString(textlines.elementAt(i).toString(),leftinset,(i)*(line_height)+line_ascent);
}

public Dimension getPreferredSize(){ return D;}
public Dimension getMinimumSize(){ return D;}
public Dimension getMaximumSize(){ return D;}
public Dimension getSize(){ return D;}
} // class





//test-Applet for our new Multilabel


import java.awt.*;

public class mltest extends java.applet.Applet{

Multilabel l;

public void init(){
 l = new Multilabel("Hello World, this is a quite long line!",100);
// l is a new Muliline-Label with a width of 100 Pixel. the height is
// calculated, returned via getPreferredSize() etc. to the responsible
// Layoutmanager.
// setFont, setBackground and setForeground can be used as before,
// the only limitation is: Multilabels are always left-aligned..

 add (l);
}


} //class

0
 
mbonneyAuthor Commented:
Adjusted points from 100 to 300
0
 
mbonneyAuthor Commented:
I wasn't expecting a complete Applet, but I'm very glad you did it.  I will study the code and fit it into my application.  I appreciate this very much.

Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now