Because the default layout manager of a JFrame 's content pane is BorderLayout and adding directly to it would fill the entire available space (i.e. , center) of the frame's content pane. On the other hand, the default layout manager of a JPanel is FlowLayout .
The FlowLayout class puts components in a row, sized at their preferred size. So adding the JList to a JPanel would not fill the entire available space.
Up vote 1 down vote favorite share g+ share fb share tw.
Below is my code for creating the JList. When it is created in a standalone JFrame the JList fills the entire frame. However, when I create it as a JPanel and add it to the JFrame it is not filling the size of the component, Why?
Public class ListBranchesInterface extends JPanel { private Library theLibrary; // reference to back end private ArrayList branches; private DefaultListModel dlm; private JList list; private JScrollPane scroll; public ListBranchesInterface(Library theLibrary) { this. TheLibrary = theLibrary; branches = new ArrayList(); branches. AddAll(theLibrary.
GetLibraryBranches()); Iterator iter = branches.iterator(); dlm = new DefaultListModel(); while (iter.hasNext()) { dlm. AddElement(iter.next().toString()); } list = new JList(dlm); // create a JList from the default list model scroll = new JScrollPane(list, JScrollPane. VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.
HORIZONTAL_SCROLLBAR_ALWAYS); // add a scroll pane // to the JList add(scroll); setVisible(true); } java swing jframe jpanel jlist link|improve this question edited Dec 25 '11 at 22:13Andrew Thompson38.1k41336 asked Dec 25 '11 at 21:56trs43319 64% accept rate.
(JPanel. )setVisible(true) This will happen by default for any component added to a visible container (e.g. A JFrame once setVisible(true) is called). – Andrew Thompson Dec 25 '11 at 22:17.
Because the default layout manager of a JFrame's content pane is BorderLayout and adding directly to it would fill the entire available space (i.e. , center) of the frame's content pane. On the other hand, the default layout manager of a JPanel is FlowLayout.
The FlowLayout class puts components in a row, sized at their preferred size. So adding the JList to a JPanel would not fill the entire available space.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.