[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Removing window border from around the TextArea AWT object

Posted on 2000-03-23
8
Medium Priority
?
724 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 1

Expert Comment

by:sankars98
ID: 2650569

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

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

Author Comment

by:mbonney
ID: 2653424
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
ID: 2654084

 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
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!

 
LVL 1

Expert Comment

by:ya87
ID: 2660696
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
 

Author Comment

by:mbonney
ID: 2661210
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 1200 total points
ID: 2665689
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
ID: 2670716
Adjusted points from 100 to 300
0
 

Author Comment

by:mbonney
ID: 2670717
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

656 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