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