0

I want to align two text in same line first text should be in left side another one should be in right side of java swing textpane. so I have using style interface and Styleconstants class to align text but it couldn't worked. I have applied some other styles on same two text like Styleconstants.setFontSize(), Styleconstants.setForeGroundColor() but it's working fine. Here my code

JTextPane pane = new JTextPane();
StyledDocument sdoc = pane.getStyledDocument();
SimpleAttributeSet rightAlign = new SimpleAttributeSet();
StyleConstants.setAlignment(rightAlign, StyleConstants.ALIGN_RIGHT);
StyleConstants.setForeground(rightAlign, Color.lightGray);
StyleConstants.setFontSize(rightAlign, 11);
sdoc.insertString(sdoc.getLength(), "name", null);
sdoc.insertString(sdoc.getLength(), "timeHis" + "\n", rightAlign);

its give the output like nametimeHis but I want like this ouput name timeHis(exact opposite side in JTextpane in same line ) Is their any wrong in my code? how to resolve this problem?

Edited by boopathyraj: changed code part

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by JamesCherrill
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.