1

I have designed a code for JTextPane, what I want to do is put that JTextPane in the bottom right corner, it is is fine as long as the form isn't resized (I want the form to be resizeable) but when it is resized the JTextPane does not move along. How can I make it stick to that right corner and move about if the form has been resized, I do not need it to cover the full contentPane. here is my code for the JTextPane

JTextPane txtpnHello = new JTextPane();
txtpnHello.setText("Hello");
txtpnHello.setEnabled(false);
contentPane.add(txtpnHello);

Thanks.

  • What is your `contentPane`? `JDialog`, `JPanel`, `JFrame`??? And are you using a [Layout manager](http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html)? – Jonathan Drapeau Jan 30 '14 at 19:29
  • What [`Layout Manager`](http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html) are you using? – PM 77-1 Jan 30 '14 at 19:29
  • You can take a look at this related [question's answers](http://stackoverflow.com/questions/7905731/how-to-put-component-in-bottom-right-corner-with-gridbaglayout?rq=1) – Jonathan Drapeau Jan 30 '14 at 19:31
  • 1
    possible duplicate of [How to make jLabels stay attached to the corners of a window form, despite resizing the form in java?](http://stackoverflow.com/questions/21463352/how-to-make-jlabels-stay-attached-to-the-corners-of-a-window-form-despite-resiz) – Paul Samsotha Jan 30 '14 at 19:38
  • Ask questions to to those who answered your previous exact question (a couple hours ago) if you don't understand something. Don't ask the exact question again. You previous question probably lacked clarity or effort on your part to get a precise answer, just as this question does. You could always edit your question with some updated information or more questions, if all you wanted was a bump. – Paul Samsotha Jan 30 '14 at 19:41

1 Answers1

1

You can use a SpringLayout Manager, perhaps like this -

SpringLayout layout = new SpringLayout();
JPanel contentPane = new JPanel(layout); // <-- Add the layout manager.
JTextPane txtpnHello = new JTextPane();
// The "Spring" for right
layout.putConstraint(SpringLayout.EAST, txtpnHello, 5,
        SpringLayout.EAST, contentPane);
// The "spring" for the bottom.
layout.putConstraint(SpringLayout.SOUTH, txtpnHello, 5, 
        SpringLayout.SOUTH, contentPane);
txtpnHello.setText("Hello");
txtpnHello.setEnabled(false);
contentPane.add(txtpnHello);
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249