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());
Related
I just recently started using Swing to create GUIs for programs, and it's been pretty fun to mess around with so far. However, I'm having an issue with a JPanel with the layout set to gridLayout. Right now it looks like this:
The grid on the right is a JPanel set to a GridLayout, with each cell being a bordered JLabel. The options on the left are also inside a JPanel, and the left JPanel and right JPanel are nested in a GridBagLayout set on a JFrame.
Essentially, my problem is that I want to "scale" the grid on the right so that each cell is a certain height and width. The grid itself will have a variable number of rows and columns, which are set when the program first starts up. Eventually, I plan to have the right JPanel in a JScrollPane (if that's how that works...), so I'm not really concerned about whether or not all of the grid shows up onScreen.
I tried setting the fill value for the gridLayout to "BOTH" and it gave me the following result:
This is closer to my intention, but I wanted the actual ImageIcon in the JLabels to fill the entire JLabel. Additionally, I would want the JLabels to be the same height and width. However, I don't know exactly how to do that. I've been messing around with it for a while now, and I'm not sure if I'm just too much of a noob with Swing, or if I'm missing something in the documentation.
In the end, I'd like the grid cells to be a fixed height and width, no matter the number of cells, and no matter whether it goes offscreen or doesn't fill it.
(Also, I just thought, maybe it's not the best idea to code this and then shove it in a JScrollPane later and expect it to perform the same.... I guess I'll just see what happens.)
but I wanted the actual ImageIcon in the JLabels to fill the entire JLabel.
Check out Darryl's Stretch Icon which will allow the icon to resize to file the space available for the JLabel.
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 have a column of JPanel instances that has content in it, that when it is clicked, the selected Panel is set to have a border (in order to distinguish it), and only 1 at a time has the border.
The problem is that when it sets the border, it sets the outer section of the panel to the border, and shrinks the content inside. Although it seems minor it is not very professional, and I would much rather have it add more like an overlay, where the content will not shrink.
I am thinking maybe there is some method of graphics that will let me do this? I haven't been able to find any way of doing this.
Start by setting all the components to have a EmptyBorder set to a single pixel inset.
When you select a panel, simply set the newly selected panel's border as you are (presumably using a LineBorder) and the set the previously selected panel's border to the single pixel EmptyBorder.
If you're clever, you could get away with a single instance of EmptyBorder ;)
In my application, I have two swing components on top of each other, that look something like this picture. The problem is that the orange component needs a vertical scrollbar, but I want the right edges of the components to stay exactly aligned (and the width can vary as the user makes the app wider or narrower). If I use something like a grid layout, the scrollbar takes up space and then the scrollbar lines up with the right edge of the red component.
I'm thinking I might need to use a scrollbar component and add that separately and use it to control the orange component. Is there a way to attach a scrollbar to another component like that? I would think it would be difficult without using a scrollpane.
I'm also open to any suggestions on how else to approach this.
It shouldn't be too hard to implement the approach you suggested. Wrap the orange component in a JScrollPane, but configure the scroll pane to hide both scrollbars. Then, set the scroll model for the vertical scroll bar in the scroll pane to the scrolling model from the standalone scrollbar. Even though the scroll pane scroll bar is hidden, it will still scroll if the models are linked. See my answer in this question for some code - it's a different application but similar principle.
Alternatively, you could use a JScrollPane with a visible vertical scrollbar, and add a spacing component next to the red component to keep it aligned. I'm thinking you could use a GridBagLayout with two columns. The first row holds the red component and the spacer, and the second row holds the scroll pane with the orange component, which spans both columns. Then, you just have to get the width of the scroll bar component from the JScrollPane and set the preferred width of the spacer to the same value. A drawback with this strategy would be that it could be difficult to keep the spacer size updated if the scrollbar width changes (due to a UI change, for example).
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.