Good evening, I am working on a small text file merging app. (for learning purposes)
The intent is to have the user select 3 text files and when they click merge, the three files are combined, some analysis is done and a JScrollPane containing the returned data should be displayed at the bottom portion of the ContentPane on the initial frame that was created. I've been trying to use WindowBuilder in Eclipse to get an idea about how GUI creation works, but I can't figure out how to set up the GUI with a ScrollPane section that is blank until the mergeFiles method runs.
I have verified that the mergeFiles method is successfully returning a good JPanel containing the expected data. I tested this by creating a new JFrame and adding that returned panel to the frame to review the data.
I'm sure I'm making a stupid mistake, but I just can't figure out how to get the updated JScrollPane added to the ContentPane of the active window. Any help would be greatly appreciated!
Set the minimum size property of you display object, then add it to the scroll pane, your display will look normal until you go beyond the displayable size, then the sliders of the scroll pane, which will then be visible, will give you the ability to scroll to see your off screen contents.
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
1) Your question is too difficult to read because your comment lines run on forever and you cant read the code/comments without scrolling the window and the text area. Make sure your code/comments are visible without the need for horizontal scrolling.
2) Post a proper SSCCE when you ask a question. Your question is about displaying a panel in a scroll pane when a button is pressed. The logic for creating the panel is irrelevant. What you need to do is update your code and include the "mergeFiles()" method. Of course we don't want your real method, we just want you to hardcode the creation of you panel with components that should cause the panel to scroll. This can be as simple as adding a few text areas by using "panel.add( new JTextArea(20, 20) )".
Once you get the basic concept working of how to dynamically add a panel to a frame, then you worry about your real processing logic. So while you create the SSCCE you can remove the other unnecessary code. All you really need is the frame with a button to create/add the scrollpane.
posted 1 year ago
Thank you for the tips, I went back this morning and started revising the code so I could provide a SSCCE and the functionality I want started working. So now I need to review the elements I removed while creating the SSCCE to see what was causing the ScrollPane to not display.
I will remember this lesson and simplify everything when I hit a roadblock and then start building again from a know good working config.
I often find my problem just by trying to create an SSCCE. At least I eliminate possible causes. This is a good technique to use even outside of a forum.
All things are lawful, but not all things are profitable.
posted 1 year ago
Indeed, I am quickly learning that the SSCCE is going to be a go to method for troubleshooting. I'm about 6 weeks into my Java journey so I have much to learn, but it sure is interesting.
posted 1 year ago
So now I need to review the elements I removed while creating the SSCCE to see what was causing the ScrollPane to not display.
I would start by NOT using a null layout and setBounds.
Swing was designed to be used with layout managers.
When using a JScrollPane, the scrollbars will appear automatically when the preferred size of the components added to the scrollpane is greater than the size of the scrollpane. If you use a null layout a panel doesn't have a preferred size. When you use layout managers the preferred size is dynamically recalculated as components are added/removed and you revalidate() the panel.