Я много гуглил, но ничего не нашел по этой теме.
Вот мой код:< /p>
hebrewField = new JTextPane();
hebrewField.setFont(ApplicationFonts.getHebrewFont(30F));
hebrewField.setDocument(new NikudStyledDocument(true));
hebrewField.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
hebrewField.setMinimumSize(new Dimension(Settings.getKeyboardWidth() - 30,
(heightTotal - heightBorderTitel)));
hebrewField.setMaximumSize(
new Dimension(this.widthTotal, (heightTotal - heightBorderTitel)));
hebrewField.setBorder(
BorderFactory.createTitledBorder(translator.realisticTranslate(
Translation.HEBRAEISCH__EINFACHE_SCHREIBWEISE)));
changeLineSpacing(hebrewField);
и
private void changeLineSpacing(JTextPane pane) {
SimpleAttributeSet set = new SimpleAttributeSet(pane.getParagraphAttributes());
StyleConstants.setLineSpacing(set, 0.5F);
pane.setParagraphAttributes(set, true);
}
Кто-нибудь еще помнит, как это сделать в Java Swing? Любые идеи приветствуются. Спасибо за вашу доброту.

ОБНОВЛЕНИЕ
Здесь текст задан. Думаю, мне нужно установить позицию курсора после вставки текста.
public void mousePressed(MouseEvent e)
{
DataButton jButton = (DataButton) e.getComponent();
String caption = jButton.getData();
JTextComponent focusElement = findFocusElement();
if (focusElement != null)
{
int position = focusElement.getCaretPosition();
String text = focusElement.getText();
String before = text.substring(0, position);
String after = text.substring(position);
focusElement.setText(before + caption + after);
focusElement.requestFocus();
}
}
ОБНОВЛЕНИЕ
Вот минимальный воспроизводимый пример:
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
public class Testing
{
public static void main(String[] args)
{
SwingUtilities.invokeLater(() -> {
javax.swing.JFrame window = new JFrame();
JPanel panel = new JPanel();
JButton buttonM = new JButton("M");
JButton buttono = new JButton("o");
JButton buttont = new JButton("t");
JButton buttonh = new JButton("h");
JButton buttone = new JButton("e");
JButton buttonr = new JButton("r");
JButton buttonSpace = new JButton(" ");
JTextPane textPane = new JTextPane();
textPane.setPreferredSize(new Dimension(580,200));
addActionListener(buttonM, textPane);
addActionListener(buttono, textPane);
addActionListener(buttont, textPane);
addActionListener(buttonh, textPane);
addActionListener(buttone, textPane);
addActionListener(buttonr, textPane);
addActionListener(buttonSpace, textPane);
panel.add(textPane);
panel.add(buttonM);
panel.add(buttono);
panel.add(buttont);
panel.add(buttonh);
panel.add(buttone);
panel.add(buttonr);
panel.add(buttonSpace);
window.add(panel);
window.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
window.setSize(new Dimension(600, 400));
window.setLocationRelativeTo(null);
window.setVisible(true);
});
}
private static void addActionListener(JButton button, JTextPane textPane)
{
button.addActionListener(event -> {
String caption = button.getText();
int position = textPane.getCaretPosition();
String text = textPane.getText();
String before = text.substring(0, position);
String after = text.substring(position);
textPane.setText(before + caption + after);
textPane.requestFocus();
// textPane.setCaretPosition(position + 1); // this was missing
});
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... ce-the-pro