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?