//in my class I declared
JPanel janswer;
// then I proceeded to make a Jpanel
public void buildAnswerPanel()
{janswer = new JPanel();
janswer.setBackground(Color.white);
janswer.setLayout(new GridLayout(2,0,));
//everything works including the next line
janswer.BorderFactory.createTitledBorder( "Here is my Title");
// however I wish to center the panel title......... so when I try the
following I get an error
janswer.setBorder(BorderFactory.createTitledBorder("Here is my Title
", TitledBorder.CENTER));
}
Please give me an example of how to "justify the title of a border on a
Jpanel"
Many Thanks
Fud
.........................................................................................
here is the error
cannot resolve symbol
symbol : method createTitledBorder (java.lang.String,int)
location: class javax.swing.BorderFactory
janswer.setBorder(BorderFactory.createTitledBord
er("Here is my Answer ", TitledBorder.CENTER));
^
.................................................................................................
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
> BorderFactory.createTitledBorder("Here is my Title ",
> TitledBorder.CENTER )
There is no such method. If you check the JavaDocs, you will find the
following createTitledBorder methods in the BorderFactory class:
createTitledBorder(Border)
createTitledBorder(Border,String)
createTitledBorder(Border,String,int,int)
createTitledBorder(Border,String,int,int,Font)
createTitledBorder(Border,String,int,int,Font,Color)
createTitledBorder(String)
Note that createTitledBorder(String,int) is not one of them. You need to
select from the defined methods and supply the correct parameters. I
think you probably want to use createTitledBorder(Border,String,int,int);
Alternatively, you can create the border using a method that does not
specify all of the attributes, then set any additional attributes that
you want using TitledBorder's accessors. For example:
TitledBorder border = BorderFactory.createTitledBorder( "Title" );
border.setTitleJustification( TitledBorder.CENTER );
--
Regards,
John McGrath
> [...]
> here is the error
> cannot resolve symbol
> symbol : method createTitledBorder (java.lang.String,int)
> location: class javax.swing.BorderFactory
>
> janswer.setBorder(BorderFactory.createTitledBord
> er("Here is my Answer ", TitledBorder.CENTER));
> ^
Indeed there is no such method in BorderFactory (see
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/BorderFactory.html).
You could try
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Here is my Answer",
TitledBorder.CENTER,
TitledBorder.TOP);
Regards,
Dirk
> BorderFactory.createTitledBorder(null,"Here is my Answer ",
> TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION)
Checking the source code, I see that passing null for the Border argument
will work. Is the behavior documented, or are you depending on internal
implementation details?
--
Regards,
John McGrath
Thanking each one of You for your quick responses and accurate info :
Roland
Dirk Starke
John McGrath
This is a wonderful ng.
Thanks much
Fud
You're probably right that it's not documented, at least not explicitly.
I guess, I must have interpreted the javadoc of createTitledBorder
("Adds a title to an existing border, ...") in combination with the
possibility to create compound borders (wrapping a border within another
border) that it should be possible. I've applied it in a number of
applications and it never failed. So I was relying on pragmatics rather
than wisdom ;-)