Caleb Garcia

Greenhorn
+ Follow
since Aug 14, 2019
Caleb likes ...
Eclipse IDE Java Windows
Merit badge: grant badges
For More
North Carolina, USA
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Caleb Garcia

Hello,

I'm attempting to download Java SDK 8 from the below link. When I accept the license agreement and click on the download link, it redirects me to login.oracle.com (every attempt) and asks me to login or signup. Is anybody else having this issue, and is there a way around it that doesn't require a before-unnecessary account creation?

Link:
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Thanks
4 years ago

Piet Souris wrote:I do not get a horizontal scroll bar. But if that is a problem, you can set the policy about the scrollbars. See the API of a JScrollPane. In my demo I set the width of the empty border right to 20, to allow for a scrollbar.


Could just be a system-by-system problem, but like you said below, it's a demo. I always forget about the policies, definitely something to remember.

Piet Souris wrote:And a 0 in the contructor of a GridLayout does mean that that part is unspecified, and that you can add as many as you like. So, (0, 1) means one column, and as many rows as necessary. Likewise (1, 0) puts all the components in one row, no matter how many components.


For something like GridLayout, that's actually a really useful piece of information. I always worked off of GridLayout being a static setup, so having dynamic rows/cols opens up for some other things. Cool!

Piet Souris wrote:The disadvantages of a GridLayout are: it does not respect preferredSizes, and it scales its components to fill the panel. But it is ideal for a demo.


This might be was I was seeing; you can essentially force a change in the size of the panels by resizing for more vertical space, adding more so they shrink, zooming back in, and then more add to that same shrunken size. It's a little odd, but it makes sense given resizing allowed.

Thanks again for the help!
4 years ago

Piet Souris wrote:Here is a simple demo that uses a GridLayout (has its disadvantages, but is very simple to use) and a JScrollPane.
Experiment with some other LayoutManagers and see what you like.



I'll gladly keep this around. Ritchie's post above gave me one solution, but I won't complain with having multiple options for one problem. Playing with it on my end, I notice that a horizontal scroll bar appears when you add a panel; is this because some of the space of the window is taken up by the vertical scroll bar on the right? Definitely not a problem, it's fixable, but it would be good to know if that was the cause.

I am also having some trouble understanding something about the GridLayout constructor params; you have 0 rows, 1 column, a 10px horizontal gap, and a 10px vertical gap. Does having 0 rows make it dynamic so you're not constrained to a specific amount?
4 years ago
Unless I'm mistaken, this is exactly what I was trying to accomplish. I've been trying to solve this for months. Thank you so much for the nod to BoxLayout!

Code base for solution, assuming class ScrollablePanel extends JFrame:

4 years ago

Campbell Ritchie wrote:Welcome to the Ranch



Thank you!


Campbell Ritchie wrote:Why are you using flow layout? What about box layout with a vertical alignment?



I believe BoxLayout is something I've tried before, but I'll look at it anyways. My attempts have been akin to unorganized chaos so I don't remember everything I've tried. I'll get back to you on that. Thanks!
4 years ago
Hello,

Quick description of the attached graphic for ease of understanding my issue; each section wrapped in a dotted line is its own panel. The main panel (containerPanel) has a BorderLayout, which holds the other three other main panels (the one with "text" is BorderLayout.NORTH, called titlePanel, has null layout; the one with four boxes is BorderLayout.CENTER, called listPanel, has FlowLayout; the bottom one with buttons is BorderLayout.SOUTH, called buttonPanel, has FlowLayout). Each dotted section in the listPanel is its own panel (list item), with a JLabel and a JButton, which is the width of the window.

One of the buttons at the bottom is an "add" button that adds a new list item to the listPanel. Unfortunately, as you can see, with four items already in the list, the fifth item will disappear behind the buttonPanel. I would like to add a vertical scroll bar to the listPanel, such that you can keep adding items and the vertical scroll bar will show up when needed so that you can scroll through the whole list. The problem with this is that (assuming the panel has a scroll pane) because the listPanel has a flow layout, if there is already one item in the list and you add a second one, it will add it to the right of the first one, and a horizontal scroll bar will appear.

I only want the items to add downwards, and I only want a vertical scroll bar. Any help is appreciated. Thank you for reading.
4 years ago