0

Hello People.

I have set up my simple Java GUI to use a JTextPane. I need it to display the following 3 lines over and over again:

  1. A line with input from a variable (aligned left)
  2. A line with output from a variable (right aligned)
  3. A blank line

Now I can set it to do this, but I have trouble with right-aligning only one line. Is there an easy way I can acheive what I am suggesting. The reason i need it is for an advanced calculator (scrollable CAS) and most of these systems have input on the right and output on the left.

I would appreciate any help you have to offer in acheiving what i mention,
Thanks in advance,
mintsmike

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by BestJewSinceJC
0

The way I would do this is to use a GridLayout. You can use the follow snippet to create a GridLayout with two columns:

GridLayout layout = new GridLayout(0,2);

Then you would add your first line, add your second line, and add a blank line TWICE. The reason for adding it twice is because there are two columns. The first line would be in the first column, the second line in the second column, and then the blank line would be in the first column again. . but you want it to cover both columns, so add two blank lines.

For other ways of doing this, look into Swing Layout Managers, but I think you'll have a harder time with most other ways. BorderLayout might work ok.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.