Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

a JTable problem

Posted on 2001-07-23
14
204 Views
Last Modified: 2008-03-10
Hi
I want my table to always have a horizontal scroll bar
but somehow when I maximize the applet the scroll bar
disappears.How Can I force the scroll bar to always
exist.


I have tried setting the policy but doesnot seem to work

This is the code

   EvLogData evLogData   = new  EvLogData();
   Object [][] data      = EvLogData.getData();
   String [] colNames    = EvLogData.getColumns();


   NoEditTableModel tabModel = new NoEditTableModel  
                        (data,colNames);

   evLogTable   = new JTable(tabModel); //define the table
   evLogTable.setBackground(Color.lightGray);
   evLogTable.setShowGrid(false);
   JScrollPane evTablePane   = new JScrollPane
                        (evLogTable);

   evTablePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    JPanel evP = new JPanel();
    evP.setLayout(new BoxLayout(evP,BoxLayout.Y_AXIS));
    evP.add(evTablePane);
    evP.setAlignmentX(Box.LEFT_ALIGNMENT);


    evP.setPreferredSize(new Dimension(400,100));
    evP.revalidate();
    evP.repaint();


p.s : actually it shows the end arrows but there is  
      nothing to scroll  something like
      an empty scroll bar



0
Comment
Question by:sanjay_thakur
  • 7
  • 3
  • 2
  • +2
14 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6310676
sanjay,

24 questions asked,
Only 6 questions graded (and 5 C's awarded).

You can't be getting that bad advice can you?

> actually it shows the end arrows but there is  
> nothing to scroll  something like
> an empty scroll bar

Well if the table fits on the panel, and there's nothing to scroll then what would you expect?





0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6310997
Hi,
I apologize!
I have been bit clumsy
but as you can see I have promptly acted !

now back to the question

>Well if the table fits on the panel, and there's nothing >to scroll then what would you expect?

That's why I need a solution

because I want to make the table like "event viewer"
refer :control panel --> administrative tools (windows)

There is always a "horizontal scroll bar"

I dont know how to achieve this
so that even if the table fits in the panel
the scroll bar exists

0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6311001
Hi,
I apologize!
I have been bit clumsy
but as you can see I have promptly acted upon your comment
!

now back to the question

>Well if the table fits on the panel, and there's nothing >to scroll then what would you expect?

That's why I need a solution

because I want to make the table like "event viewer"
refer :control panel --> administrative tools (windows)

There is always a "horizontal scroll bar"

I dont know how to achieve this
so that even if the table fits in the panel
the scroll bar exists

0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 92

Expert Comment

by:objects
ID: 6311443
> I have promptly acted upon your comment

Thank you very much :)

> because I want to make the table like "event viewer"

I just looked at Event Viewer on W2K and it disappears when not needed.

To do what you want you just need to make the size of the scrolled component bigger than the viewport. Try setting the width of your table to a large number.


0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6313560
hi,

I added this
evLogTable.setPreferredSize(new Dimension(screenSize));

but the problem is

the table columns are resized by default to fit in the
available space hence there is no scroll bar

I tried
evLogTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

but this leads to many problems

like I cannot size the columns properly.

How can I add scrollbar without
this
evLogTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

HElp!!!

0
 

Expert Comment

by:rwoodruf
ID: 6313844
sanjay,

Try this:

JScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

Please grade if this works.

Hope this helps.

-- Rodney
0
 

Expert Comment

by:rwoodruf
ID: 6313856
Sanjay,

I mean to say:

evTablePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

-- Hope this helps.
0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6313878
I already have this in my code

if u refer the code posted

This doesn't work.

0
 

Expert Comment

by:rwoodruf
ID: 6313899
So you're saying that you want the scrollbar to be active whether it is needed or not?  You want to be able to scroll no matter the circumstance.

If this is the case, then there is absolutely no way to do this.  Can I ask why you would want a active scrollbar when there is nothing that needs to be scrolled?

-- Rodney
0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6315744

ok I rephrase the question

if I set table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
I am able to get
the scrollbar but there is a gap left
between the rightmost boundary of the table and the last column.

How do I remove this gap.

p.s: How can I know the current size of the applet
for example if the user changes the size of the applet is there
any way/event to know that change







0
 
LVL 4

Accepted Solution

by:
kylar earned 30 total points
ID: 6319150
You can set a component listener and catch Component Resize events.
 if you have a JTable that doesn't take up all the room in a scrollpane (because the column widths don't fill the space) then you will always get the empty space. You can re-size the JScrollPane instead, and make sure that it fits the JTable (with a little munging), but you don't really have too many options here.

Kylar
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6956133
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20180059.html
http://www.experts-exchange.com/questions/Q.20221686.html
http://www.experts-exchange.com/questions/Q.20234788.html
http://www.experts-exchange.com/questions/Q.20246190.html
http://www.experts-exchange.com/questions/Q.20256943.html
http://www.experts-exchange.com/questions/Q.20257803.html
http://www.experts-exchange.com/questions/Q.20257760.html
http://www.experts-exchange.com/questions/Q.20260496.html
http://www.experts-exchange.com/questions/Q.20263573.html
http://www.experts-exchange.com/questions/Q.20263541.html
http://www.experts-exchange.com/questions/Q.20266174.html
http://www.experts-exchange.com/questions/Q.20283765.html
http://www.experts-exchange.com/questions/Q.20288327.html
http://www.experts-exchange.com/questions/Q.20291180.html
http://www.experts-exchange.com/questions/Q.20291602.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20155817.html
http://www.experts-exchange.com/questions/Q.20169826.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6961062
Hi I would like to accept kylars solution as the answer

0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6961067
Hi I have accepted kylars solution as the answer

I couldnot get anything else work

I still dont think that this is a neat solution
but this is the one that works

Thanks everyone
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 46
use lov values 2 63
ejb wildfly example 2 25
sql import cannot be resolved jsp 3 49
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question