Java swing : StyledDocument padding and radius for paragraphs

89 views Asked by At

I'm using StyledDocument and SimpleAttributeSet for my project but I'm having an UI issue.

Here is what I have with my code right now : enter image description here

And here is what I would like to have : enter image description here

The first thing I'm trying to have is the padding, because the background is too "tight" and so we see a lot of text and not a lot of blue but I don't know how to make the blue surface bigger.

And then, if I can apply a radius it will be perfect but I can't manage to do it neither.

Here is the code you'll need to reproduce what I have on the first image :

 StyledDocument doc = chatBox.getStyledDocument(); 

 SimpleAttributeSet rightO = new SimpleAttributeSet();
 StyleConstants.setBackground(rightO, new Color(59,130,247));
 StyleConstants.setForeground(rightO, new Color(255,255,255)); 
 StyleConstants.setFontSize(rightO, 14);

 SimpleAttributeSet blue = new SimpleAttributeSet(); 
 StyleConstants.setAlignment(blue, StyleConstants.ALIGN_RIGHT);
 StyleConstants.setRightIndent(blue, 10);
 StyleConstants.setLeftIndent(blue, 100);

 try {
 doc.insertString(doc.getLength(), "\n"+message.getContent(), rightO);
 doc.setParagraphAttributes(doc.getLength() -    message.getContent().length(), doc.getLength(), blue, false);
 } catch (BadLocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
 }
   
0

There are 0 answers