I have a TextArea in LWUIT that I am having an issue manipulating. I have the following two issues:
Even though I call setIsScrollVisible(true), I do not seem to have a
scrollbar and cannot scroll when the output goes below the visible
area of the container.
How do I tell the TextArea to automatically scroll to the bottom
programmatically?
My code for initializing the TextArea looks like this:
myTextArea = new TextArea(20, Display.getInstance().getDisplayWidth());
myTextArea.setEditable(false);
myTextArea.setEnabled(true);
myTextArea.setIsScrollVisible(true);
myTextArea.setGrowByContent(false);
System.out.println(myTextArea.isScrollableY());
isScrollableY() returns true. Any ideas? Is there something I am missing? There doesn't seem to be anything visible in the API that lets me explicitly enable or disable scrolling. Thanks in advance for any assistance on this.
The width of the text area is in columns NOT pixels as you have in your code.
Setting the scroll to visible won't cause it to appear since LWUIT scrollbars are always "as needed" which means a scrollbar will only appear when necessary, setting this value to false would just hide the scrollbar regardless of necessity.
To have the text area grab the entire width just place it within a box layout Y container/form and the layout manager will stretch it on the X axis.
You can use scrollRectToVisible() to scroll the text area to the bottom or alternatively you can derive text area and use setScrollY(int) with the appropriate value (see the source code of text area for how this is used to scroll the text area.
Try a simple textArea.setFocusable(false). This worked for me.
Related
I am using a JTable to display data with custom TableCellRenderer.
Everything works fine despite there appears a small "area" in the right upper corner when having a vertical scrollbar. I want to render that area transparent, is this possible?
I want to render that area transparent, is this possible?
Not really sure what you mean. That area is rendered transparent. All you see is the background of the scrollpane.
However you can place your own component in that area if you wish. Check out the section from the Swing tutorial on Providing Custom Decorations for a JScrollPane.
The example shows how to add a custom component to the top/right of the scrollpane using:
pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new Corner());
In the TextArea widget of Java FX 2.2, the method getScrollLeft is described in the documentation as returning
The number of pixels by which the content is horizontally scrolled.
More precisely, it accesses the value of the property ScrollLeft which has the above description.
When I slide either the horizontal or vertical scrollbar, this variable is adjusted, as expected. However when I press "backspace" on a line that is longer than the screen width such that the scroll amount decreases, or at the first character of a row, the property is not adjusted even though the scroll position changes.
A hacky way to fix this is to access the scrollbar directly, get how much of it is being scrolled, and calculate the appropriate value based on that information. I'd prefer not to do this.
Is there an accepted way to solve this problem, or am I misusing the scrollbar information?
I have an application that uses a JLabel and a JPanel. These components have a MatteBorder. When the components are created, the border is the default. When I click on the components, I set the border to a different thickness to make a select appearance. The problem comes when I want to unselect and I set the border to another thickness. This time the border is not modified and looks the same.
I'm not seeing what the problem is, because the first modification of the border thickness works fine.
Although this might be a hacky approach, try to repaint() the view, sometimes it just glitches.
I read this:
http://docs.oracle.com/javase/tutorial/uiswing/components/border.html
when working on my program.
I'm using JXMultiSplitPane (from SwingX 1.6.2) to implement a three-pane horizontal interface. In the center pane is a JTabbedPane with two tabs: one with a JTextArea (in a JScrollPane, of course) used for entering Markdown code and the other a JEditorPane (again, in a scroll pane) for displaying a rendered HTML preview. When the user switches to the preview pane, the text in the editor is processed and displayed in the preview pane.
My problem is that if I enter text in the editor with long lines, and then switch to the preview, the center pane will expand. Sometimes it's just by a little bit, other times it'll take up more room than is actually on the screen. But if I move one of the resize handles manually, everything will snap back in place.
I've found only two ways to deal with this before it happens:
Manually resize one of the panes before entering any text.
Give the center pane a weight of 1 in the MultiSplitLayout model.
I can't use the second one since it will expand the center pane to take up almost the whole window by default.
Is there a way to fix this?
Update
After a little more testing, even technique (2) doesn't keep the size constant; switching between the two tabs changes the size of the center pane slightly.
I now believe that the problem is partly with the tabbed pane. The JTextArea and the JEditorPane do not have the same size and that JTabbedPane is resizing when I switch between them (since I'm resetting the JEditorPane text every time. This wouldn't be a problem except that JXMultiSplitPane will keep automatically resizing the center pane until the user forces a specific size by resizing manually.
So I should be able to fix the issue by making the size of the JTabbedPane fixed, but still able to be resized by the handle bars. Any tips on doing that?
The MultiSplitLayout is .. a LayoutManager, so you have to understand how it works (me too, not overly familiar with it myself :-)
The basic layout happens according to the component's prefSize, the weights are for distributing excess/missing space relative to the pref. By default, the dividers are "floating", that is they are positioned between the components as layouted by the basic mechanism. The moment a user touches a divider, dividers are "not-floating", comp sized to fit in-between the dividers. That's the reason for you not seeing the size-greed after moving the divider once. So one ways out is to
setup the JXMultiSplitPane as usual, add the components and realize the frame
fix the dividers after the manager has done its initial layout
String layout = "(ROW " +
"(LEAF name=selector weight=0.15)" +
"(LEAF name=center weight=0.7)" +
"(LEAF name=list weight=0.15)" +
")";
JXMultiSpitPane pane = new JXMulitSplitPane((MultiSplitLayout.parseModel(layout))
// add components and realize the frame
...
pane.getMultiSplitLayout().setFloatingDividers(false);
Alternatively, give more weight to the weights - force the layoutManager to use them for the layout itself (instead of only for the distribution of excess/missing space). A side-effect is that the prefSize of the comps might be set (by the layout, which is a no-no-never, but who's perfect ;-)
pane.getMulitSplitLayout().setLayoutByWeights(true);
Not sure which way I would prefer or if/how that could be made easier in the multisplit ..
I created a JFrame initialized with a BorderLayout and a JScrollPane as its CENTER element.
The scroll pane is set with VERTICAL_SCROLLBAR_ALWAYS and HORIZONTAL_SCROLLBAR_NEVER policies. The intent of my frame is to have a controlled width, while the height should grow/shrink as data is added/removed.
Inside my scroll pane, I added a simple JPanel (lets call it the content panel) which is initialized with a FlowLayout (and LEADING policy).
In order to test this, I simply populate my content panel with 20 JLabel("Item " + n) components where n is the loop counter.
I would expect to see my labels shown on a single row if the frame is large enough and the labels wrap to other lines when I shrink the width. But instead, there is only a single line displayed with no wrapping... ever.
Does anyone know why the flow layout does not wrap when a scroll pane is involved?
If I remove the scroll pane all together and put the content panel directly in the frame, the desired wrapping effect occurs, but if the frame height is shrunk smaller than the content panel height it just disappears.
The idea is that I want my labels to be wrapped when necessary but also always be visible if it means having to scroll up/down.
Any suggestions on how to fix this?
Thanks.
Wrap Layout gives an explanation and a solution.
If you work with the designer, you have to set the prefferedSize property to null (delete what is set) then set the preferred size by clicking the triple dots [...] button next to the prefferedsize property name and put your preferred value.
I encountered the same problem and it works for me.