Solved

Removing window border from around the TextArea AWT object

Posted on 2000-03-23
8
705 Views
Last Modified: 2013-12-29
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
Comment
Question by:mbonney
  • 4
  • 2
  • 2
8 Comments
 
LVL 1

Expert Comment

by:sankars98
Comment Utility

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

        scrollpane.setBorder( BorderFactory.createEmptyBorder());
0
 

Author Comment

by:mbonney
Comment Utility
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
 
LVL 1

Expert Comment

by:sankars98
Comment Utility

 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
 
LVL 1

Expert Comment

by:ya87
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:mbonney
Comment Utility
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
 
LVL 1

Accepted Solution

by:
ya87 earned 300 total points
Comment Utility
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
 

Author Comment

by:mbonney
Comment Utility
Adjusted points from 100 to 300
0
 

Author Comment

by:mbonney
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bunnyEars2 challenge 6 66
mapShare challenge 13 68
Where to store the queries for modification of table 4 25
Java DateChooser? 2 0
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now