Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2004

Tip: Looking for answers? Try searching our database.

Center Text in JTextPane

Thread view: 
Guy Sussman - 01 Apr 2004 08:22 GMT
I am attempting to center text in a JTextPanel as illustrated in the
code fragment below.  Regardless of the value of second arg in the
call to StyleConstants.setAlignment(AttributeSet, int), the text
always starts at the left margin.  Can anyone please help?  Thanks in
advance

        setLayout( new BorderLayout() );
       
        //add a JSlider to BorderLayout.CENTER

        JTextPane instructTextPane = new JTextPane();
        SimpleAttributeSet aSet = new SimpleAttributeSet();
        StyleConstants.setBackground(aSet, Color.gray);
        StyleConstants.setAlignment(aSet, StyleConstants.ALIGN_CENTER);
        instructTextPane.setCharacterAttributes(aSet, true);
        instructTextPane.setBackground(Color.gray);
        instructTextPane.setEditable(false);
        instructTextPane.setText("Move Slider to Adjust Tablet");

        JPanel instructPanel = new JPanel();
        instructPanel.setLayout( new BorderLayout() );
        instructPanel.add(instructTextPane);
        add(instructTextPane, BorderLayout.NORTH);
Christian Kaufhold - 01 Apr 2004 12:09 GMT
> I am attempting to center text in a JTextPanel as illustrated in the
> code fragment below.  Regardless of the value of second arg in the
> call to StyleConstants.setAlignment(AttributeSet, int), the text
> always starts at the left margin.  Can anyone please help?  Thanks in
> advance

It is a paragraph attribute.

Christian


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.