Java tutorial
import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextPane; public class Main { public static void main(String[] args) { final JTextPane pane = new JTextPane(); pane.setText("Some text"); JButton buttonButton = new JButton("Insert label"); buttonButton.addActionListener(e -> { JLabel label = new JLabel("label"); label.setAlignmentY(0.85f); pane.insertComponent(label); }); JPanel panel = new JPanel(new BorderLayout()); panel.add(buttonButton, BorderLayout.SOUTH); panel.add(pane, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.setSize(400, 200); frame.setVisible(true); } }