Results 1 to 2 of 2
Thread: GUI, JList with scrollbar
- 12-14-2012, 10:41 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
GUI, JList with scrollbar
I'm trying to program a a gui that gives a list to select from, problem I'm having is the the list is long and is running outside the boundaries of the window so I have to expand the size of thewindow to see the whole list. I want to solve this by just having a scroll bar and then my window size won't have to change. Below is the window constructor I'm using and I've been trying to use a JScrollBar with no luck. Something makes me think it has to do with the flow layout and the area of the JList isn't set so I feel like that could be a component as well, I'm just unsure what or how to do this. Any help is appreciated.
Java Code:public class Window extends JFrame { public Window(){ super("Recipe Select"); this.setSize(400, 400); this.setLayout(new FlowLayout()); String file_name = "C:/test.txt"; String[] aryLines = null; try { ReadFile file = new ReadFile(file_name); aryLines = file.OpenFile(); } catch (IOException e) { System.out.println( e.getMessage() ); } JLabel message = new JLabel("Choose recipe to edit:"); this.add(message); JList list = new JList(aryLines); this.add(list); JButton button = new JButton("Edit"); this.add(button); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
- 12-15-2012, 12:10 AM #2
Re: GUI, JList with scrollbar
Moved from New to Java.
I don't see a JScrollBar or JScrollPane in the code you posted. Read the API for JScrollPane and follow the link to the Swing tutorial on How to Use Scroll Panes. There are also examples in the tutorial on How to Use Lists, linked from the API for JList.
Separately, note that naming your own class the same as one that exists in the standard JDK can lead to obscure problems. I strongly recommend you name that class something other than Window.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
JList with a scrollbar
By tom2zip in forum New To JavaReplies: 2Last Post: 01-19-2012, 08:23 AM -
Help with JList selection showing values on another JList
By SpO0KIe in forum AWT / SwingReplies: 4Last Post: 01-10-2012, 01:05 PM -
scrollbar not coming on jlist
By silversurfer2in in forum AWT / SwingReplies: 8Last Post: 06-22-2010, 11:07 AM -
ScrollBar in a JList
By lupo in forum AWT / SwingReplies: 2Last Post: 05-20-2010, 10:42 PM -
JList with ScrollBar
By Psyclone in forum AWT / SwingReplies: 5Last Post: 02-12-2010, 04:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks