Vertical alignment in a JTextArea - swing

I have been given a very specific requirement on how to display a list of messages. Each message can be up to 3200 characters long. For this particular display of the messages, only the first two lines of each are to be displayed, showing whatever fits of the message with the original format intact (tabs, spaces, newlines). The messages are to be contained in a JInternalFrame. When the user drags a side of the frame to increase or decrease its width, the visible text of a message is supposed to increase or decrease along with the frame, no horizontal scroll bar is desired.
I was able to get the desired behaviour with the text increasing/decreasing with the width of the frame using the following:
JTextArea ta = new JTextArea();
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setRows(2);
ta.setEditable(false);
ta.setOpaque(false);
ta.setText(longString());
ta.setAlignmentY(TOP_ALIGNMENT);
JScrollPane scrollPane = new JScrollPane(ta);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
A list of scrollPanes are added to a JScrollPane with a vertical scroll bar but no horizontal scroll bar in the JInternalFrame.
The problem I am having is that the text is resting on the bottom of the JTextArea, so the user sees the last two lines of the message, not the first two lines. It appears to be possible to set the horizontal alignment, but not the vertical alignment. Is there some way to get the automatically expanding/contracting text with text alignment at the top?

This is something that's bugged me in the past as well. It has to do with how JTextComponents interact with JScrollPanes - specifically, there is a (invisible, when non-editable) Caret that ends up at the end of your JTextComponent. When the viewport tries to figure out what it should be viewing, it looks at the caret.
So, tell the JTextArea not to move the caret during your initialization block:
DefaultCaret c = new DefaultCaret();
c.setUpdatePolicy( DefaultCaret.NEVER_UPDATE );
ta.setCaret( c );

After loading text into the text area you can use:
textArea.setCaretPosition(0);

Related

ssrs : box sneaking to the left side of the footer

I'm creating a footer on my report, with 3 boxes. One on the left side, the second one in the middle and the last one on the right side.
The left box and right box are appearing on each page, respectively with the timestamp info for the left box and for the number of pages for the right box.
Middle box is appearing , at the last page of the report only.
I've put the following line for my middle box
iif(Globals!PageNumber = Globals!TotalPages, False, True)
The script says the middle box will only appear at the last page of the report
Last page is fine. Three boxes, standing side by side.
Issue lies from the first page to the penultimate page.
As the middle box does not appear until the last page, the right box is shifting to the left side , taking over the place where the middle box should be.
I tried to fix this issue, by putting all the boxes in a rectangle. Alas no good news
I set the option Keep Together = True but I don't think it will help. I keep looking for a solution.
Any insights you may have , are more than welcome
Cheers
Update :
This is my last page
My second page to my penultimate page look like this
I want the third box to be on the extreme right side , like on my last page
If I'm interpreting your question correctly, then the middle textbox has the following two properties set:
Visibility (hidden): =IIF(Globals!PageNumber = Globals!TotalPages, False, True)
The value is : "13779..." or some expression evaluating to this.
Try changing these properties to the following:
Visibility(hidden): False
Then
Value: =IIF(Globals!PageNumber <> Globals!TotalPages, Nothing, "13779...")
This way you are not hiding the textbox itself, just the text that it displays. Doing so should cause the textbox to align the same horizontally on all pages.
For the rightmost box make the right align the text.
Either by clicking on the menubar
OR
Change the textbox property TextAlign to Right
Another method will be to write an expression in Left padding for the rightmost text box.
Something Like
=iif(Globals!PageNumber = Globals!TotalPages, '2pt', '220pt')

How put text scrollbar in Flash (actionscript 3) in specific line?

I have used the Flash UIScrollbar component to scroll my texts which i have imported externally. Is it possible manipulate the scrollbar to put it in specific line of text? In default the scrollbar placed at the beginning of the text, but I want to it placed at the end or middle or specific line of text.
scrollPosition : Number Gets or sets the current scroll position and
updates the position of the thumb.
example:
myScrollBar.scrollPosition = 45;
Source:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/controls/ScrollBar.html

JTextAreas on JPanel inside JScrollPane does not show properly

I have created a demo by swing and I want to show full text in textarea. I want to add two textarea into a scroll bar to show all component within a scroll bar. So to do that, I create a panel and then add two textarea on this one and then I add this panel into scroll bar. When I running demo, it show correctly and it also show correctly when I resize window larger but it have problem when I resize smaller screen. It does not wrap the text when resize the screen smaller (instead of appearing horizontal scroll bar).
Can you help me to automatically wrapped when resize the screen smaller.
Here my code:
JPanel gui = new JPanel(new GridLayout());
gui.setBorder(new EmptyBorder(2, 3, 2, 3));
JTextArea area = new JTextArea("JTextArea on JPanel inside JScrollPane does not resize properly");
area.setWrapStyleWord(true);
area.setLineWrap(true);
gui.add(area);
JTextArea area1 = new JTextArea("JTextArea on JPanel inside JScrollPane does not resize properly");
area1.setWrapStyleWord(true);
area1.setLineWrap(true);
gui.add(area1);
gui.setBackground(Color.WHITE);
JScrollPane scroller = new JScrollPane(gui);
//scroller.setBorder(new EmptyBorder(2, 3, 2, 3));
JFrame f = new JFrame("Big Text Fields");
f.add(scroller,BorderLayout.CENTER);
// Ensures JVM closes after frame(s) closed and
// all non-daemon threads are finished
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// See http://stackoverflow.com/a/7143398/418556 for demo.
f.setLocationByPlatform(true);
// ensures the frame is the minimum size it needs to be
// in order display the components within it
f.pack();
// should be done last, to avoid flickering, moving,
// resizing artifacts.
f.setVisible(true);
Just omit the scroll pane and make the text area a direct child of the container.
JTextArea does change its preferred size based on the text it contains. From the documentation:
java.awt.TextArea has two properties rows and columns that are used to determine the preferred size. JTextArea uses these properties to indicate the preferred size of the viewport when placed inside a JScrollPane to match the functionality provided by java.awt.TextArea. JTextArea has a preferred size of what is needed to display all of the text, so that it functions properly inside of a JScrollPane. If the value for rows or columns is equal to zero, the preferred size along that axis is used for the viewport preferred size along the same axis.

Swing: JPanel on JScrollPane - how to jump and move focus to show a specific part of the panel

I have a very long jpanel on a jscrollpane.
I want to be able to jump to a location in the panel.
is there a way to jump to a specific point in the pane?
Setting the horizontal scrollbar value is not enough
Is there a way to mark a position and jump to it (rather than giving X,Y)?
Thanks.
See scrollRectToVisible for scrolling.
Not sure what you mean with "mark a position" but if you want to scroll to for example a text field that is a (direct) child of the panel than you would do:
panel.scrollRectToVisible(textField.getBounds());

In SSRS, can you set a rectangle to grow with its contents?

I'm working on a report in SSRS (SQL Server Reporting Services) right now, and I'm having a problem getting a rectanlge I draw on the page in the report designer to grow. Basically, I've got a rectangle drawn, and then I put a text field inside of it. The contents of this text field can be either very short or very long, so I want it to grow to accomodate its contents.
But when I enter the long text, the textbox grows and then sticks outside of the lines of the rectangle. From the SSRS documentation I read, it says rectangles should grow to contain the items within them, and that those items are "peers".
What gives?
The only way I can get a textbox to breach the border of a rectangle is if the textbox is not actually inside the rectangle, but instead is underneath it.
When the textbox is inside the rectangle, and when the textbox property CanGrow = TRUE then the textbox and its rectangle both grow vertically downward to accommodate large amounts of text.
I was seeing the same issue. My problem was that I had the text boxes first and then put the rectangle around it and sent it to the back. Once I dragged the text boxes off and then back onto the rectangle, it grew properly.
You can tell whether the textbox is in the rectangle or on the body (e.g.) by looking at the Parent property of the textbox. If the textbox is outside of the rectangle, it works well to cut the textbox and paste it into the rectangle. I've had issues at times when trying to drag objects into (onto) a rectangle.
Maybe a little late - but it may help someone later.
The rectangle can serve as a container.
To turn the rectangle into a container, create the rectangle first. Just drop your other child-object elements (e.g. lists, tables, etc) into the container.
However, you cannot create the container after creating the child objects.