473,416 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Swing Jlist LayoutOrientation Problem

Hi all,

I've bumped into an odd problem creating a GUI in swing. As you will see in the screenshots, I have a tabbed layout. Each tab is a Jpanel. On this panel I have put a JList, containing a series of objects. My intention is to have a single column of objects in the list, and have it to scroll when the objects exceed the vertical space.

My code is this:

Expand|Select|Wrap|Line Numbers
  1. private JComponent createListBox() {
  2.         Object[] test = {"Thingy 1","Thingy 2",...};
  3.         JList list = new JList(test);
  4.         list.setLayoutOrientation(JList.VERTICAL_WRAP);
  5.         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  6.         list.setSize(385, 480);
  7.         list.setPreferredSize(new Dimension(385, 480));
  8.  
  9.         list.setVisibleRowCount(-1);
  10.         list.setPreferredSize(new Dimension(385,480));
  11.         JScrollPane listScroller = new JScrollPane(list);
  12.         return listScroller;
  13.     }
I know it should not be VERTICAL_WRAP, do read on.

When I use VERTICAL_WRAP I get this:



It's more than one column, I agree, but atleast it works.
When I use VERTICAL (which should be the option for what I intend to do) I get this:



My JList is squashed. It appears it doesn't take the set sizes into account.

I have little experience in creating GUI's, and I haven't found a solution. I hope you can help me.

Thanks.

The layoutManger on the pannel is a FlowLayout btw.
Oct 17 '09 #1

✓ answered by pbrockway2

It might be useful to read the section in Sun's Tutorial on Sizing a Scroll Pane.

It describes the general mechanism for "scrolling savvy" clients like JList where size is determined by getPreferredScrollableViewportSize() and the default value this has for a JList. It also describes how getPreferredScrollableViewportSize() may be affected by other methods: in particular for JList it discusses the effect of setVisibleRowCount().

2 2856
pbrockway2
151 Expert 100+
It might be useful to read the section in Sun's Tutorial on Sizing a Scroll Pane.

It describes the general mechanism for "scrolling savvy" clients like JList where size is determined by getPreferredScrollableViewportSize() and the default value this has for a JList. It also describes how getPreferredScrollableViewportSize() may be affected by other methods: in particular for JList it discusses the effect of setVisibleRowCount().
Oct 17 '09 #2
Thank you, I read the javadoc for getPreferredScrollableViewportSize(), and it helped. I don't have scrollbars but at least my window is visible. Displaying the scrollbars shouldn't be difficult.
Oct 18 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roman Thurnherr | last post by:
Hi all I'm using two JLists with the same MouseListener in a JFrame. How can I find out on which JList the MouseEvent was released? Is it generally possible or should I use a MouseListener for...
1
by: Heath Howard | last post by:
I have two questions for which I have yet to figure out an answer: 1. I have a page with three webpartzones, one zone on each row of a three-row table. I have the layoutorientation property set...
1
by: Salha | last post by:
Hello there, Can you help me in following problem: Am working on a chemistry dictionary. I want to have all the chemistry terms in a JList and whenever i select a term from a JList, it displays...
0
by: paoparaopao | last post by:
Hi, I want to drag rows up/down in a JList; for example, drag 3rd row to 1st row. I have setDragEnabled(true) for JList, but it doesn't work! How do I drag rows in JList? Thanks!
4
Nepomuk
by: Nepomuk | last post by:
Hi! I'm trying to use a JList. Here's the code: String languages = { "deutsch", // german "english", // english "castellano", // castilian "français", //...
8
by: sukatoa | last post by:
I came from List in awt.... Im currently having an experiment about JList.... say like 140,280 ( h,w ) i have 4 values that have been set on JList using addElement from...
2
by: wishbone34 | last post by:
Hi, here is some of my code public class ControlIL extends JFrame implements ActionListener, ListSelectionListener { private JList Items; //builds the UI public ControlIL(){ ...
6
by: r035198x | last post by:
I have put together this article to give people starting Swing an awareness of issues that need to be considered when creating a Swing application. Most of the Swing tutorials that I have seen just...
2
by: Gangreen | last post by:
hi, I have an arrayList in my program that I want to display in a Jlist. I need the JList to update his contents when the elements in the arraylist change/ an element is added/deleted/... I'm...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.