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
Solved

Removing window border from around the TextArea AWT object

Posted on 2000-03-23
8
713 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
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
difference of if loops 23 60
How  can  i  resolve  HTTP Status 404 -? 8 41
add projects t working set in maven 2 16
jsp error 6 25
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

791 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