473,320 Members | 2,071 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,320 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 2850
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.