Scrollpane not scrolling

T

timasmith

Hi I have a split pane with the right side containing a panel.

On the panel is a JScrollPane with a JTable on top.

No scrollbars appear when the table is populated - rather the table
squishes the column widths in order to have all columns appear.

How do I stop the JTable from doing that, and make it widen -
activating the scroll bars on the parent form JScrollPane

thanks

Tim
 
K

Kent Paul Dolan

timasmith said:
Hi I have a split pane with the right side containing a panel.
On the panel is a JScrollPane with a JTable on top.
No scrollbars appear when the table is populated - rather the table
squishes the column widths in order to have all columns appear.
How do I stop the JTable from doing that, and make it widen -
activating the scroll bars on the parent form JScrollPane

I don't have the brains or energy to test this, so consume with
salt, but: it sounds like the problem you have is that the
JTable is adjusting itself to its immediate container. If the
JTable object cannot have its Size, MinimumSize, MaximumSize,
and PreferredSize attributes set to control the self-shrinking
you are seeing, put a JPanel container between the JScrollPane
and the JTable, set the sizes for the JPanel, and see if that
fixes the problem. Hypothetically, the JTable would then adjust
itself to the containing JPanel, and the JPanel would _not_
adjust itself to the containing JScrollPane.

xanthian.

I find that Java's size/layout behavior is arcane and filled
with unexpected consequences, many times just ignoring *Size
settings entirely, which can often be overcome by breaking
the layout problem down into smaller pieces and nesting them
more deeply and in greater variety.

Is this a common perception, or am I merely clueless about
doing layouts easily?
 
I

IchBin

Hi I have a split pane with the right side containing a panel.

On the panel is a JScrollPane with a JTable on top.

No scrollbars appear when the table is populated - rather the table
squishes the column widths in order to have all columns appear.

How do I stop the JTable from doing that, and make it widen -
activating the scroll bars on the parent form JScrollPane

thanks

Tim

Try this with any of the below options:

jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

AUTO_RESIZE_ALL_COLUMNS
During all resize operations, proportionately resize all columns.

AUTO_RESIZE_LAST_COLUMN
During all resize operations, apply adjustments to the last column only.

AUTO_RESIZE_NEXT_COLUMN
When a column is adjusted in the UI, adjust the next column the opposite
way.

AUTO_RESIZE_OFF
Do not adjust column widths automatically; use a scrollbar.

AUTO_RESIZE_SUBSEQUENT_COLUMNS
During UI adjustment, change subsequent columns to preserve the total
width; this is the default behavior.


--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
O

Oliver Wong

Kent Paul Dolan said:
I find that Java's size/layout behavior is arcane and filled
with unexpected consequences, many times just ignoring *Size
settings entirely, which can often be overcome by breaking
the layout problem down into smaller pieces and nesting them
more deeply and in greater variety.

Is this a common perception, or am I merely clueless about
doing layouts easily?

Assuming you're talking about Swing, I feel the same way. I like SWT's
layout managers though; particularly GridLayout.

- Oliver
 
I

IchBin

Oliver said:
Assuming you're talking about Swing, I feel the same way. I like
SWT's layout managers though; particularly GridLayout.

- Oliver

Surprised more people do not used JGoodies Form Layout. Maybe they do
not know about it?


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
L

Larry Barowski

IchBin said:
Surprised more people do not used JGoodies Form Layout. Maybe they do not
know about it?

In all seriousness, I think they should change the company
name. The word "goodies" just doesn't inspire confidence.
 
I

IchBin

Larry said:
In all seriousness, I think they should change the company
name. The word "goodies" just doesn't inspire confidence.

Maybe.. I just can not remember my first impression based on its name.

If I had a book that was wrapped in an ugly old tattered binding with no
title, I my shy away from it not knowing the contents may contain
"Relativität: Die speziellen und allgemeinen Theorien" and never know it...

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
O

Oliver Wong

IchBin said:
Surprised more people do not used JGoodies Form Layout. Maybe they do not
know about it?

When I work for someone else, whatever they decide to use (be it Swing,
SWT or anything else), that's what I have to use.

When I'm working on my own personal projects though, they tend to be
small, and if I plan on distributing them, I don't want to inflate the size
by including lots of JARs. When I'm writing for the "plain" Java platform, I
use Swing, and when I'm writing for the Eclipse platform, I use SWT.

All of the above is assuming that I were JGoodies were available for me
to use for free; but from what I understand, you have to pay a license to
use it ($885 USD for 1 developer, 1 year?).

I guess I just haven't looked at JGoodies yet because I don't know what
problem it would solve for me that would be worth the extra JAR(s), and the
money.

- Oliver
 
I

IchBin

Oliver said:
When I work for someone else, whatever they decide to use (be it
Swing, SWT or anything else), that's what I have to use.

When I'm working on my own personal projects though, they tend to be
small, and if I plan on distributing them, I don't want to inflate the
size by including lots of JARs. When I'm writing for the "plain" Java
platform, I use Swing, and when I'm writing for the Eclipse platform, I
use SWT.

All of the above is assuming that I were JGoodies were available for
me to use for free; but from what I understand, you have to pay a
license to use it ($885 USD for 1 developer, 1 year?).

I guess I just haven't looked at JGoodies yet because I don't know
what problem it would solve for me that would be worth the extra JAR(s),
and the money.

- Oliver

Naturally, the client dictates what layout manager is used. If they know
what their requirements dictate.

No, actually they have a free version for their Forms, Looks, Animation,
Binding and Validation. The product, at cost, is their Swing Suite. All
come with extensive examples and api docs, even though freeware.

You can get the free libs at:
http://www.jgoodies.com/freeware

As to size this is what it works out to if you want to use any
particular one of them:

Forms 84k
Looks 359k
Animation 54k
Binding 159k
Validation 45k

Here is a program as an example of what it would look like. I used it to
model a layout I was testing. Forms provides you four ways(Classes) to
build you GUI. I took this path.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;

import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.debug.FormDebugPanel;
import com.jgoodies.forms.debug.FormDebugUtils;
import com.jgoodies.forms.factories.Borders;
import com.jgoodies.forms.factories.ButtonBarFactory;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

public class InsertModel {

protected static final boolean DEBUGMODE = false;
static private JFrame frame = new JFrame();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JTextField jTextField1 = new
JTextField();
private JTextField jTextField2 = new
JTextField();
private JTextField jTextField3 = new
JTextField();
private JTextField jTextField4 = new
JTextField();
private JTextField jTextField5 = new
JTextField();
private JTextField jTextField6 = new
JTextField();
private JTextField jTextField7 = new
JTextField();
private JTextField jTextField8 = new
JTextField();
private JTextField jTextField9 = new
JTextField();
private JTextArea jTextArea1 = new JTextArea();
private JTextArea jTextArea2 = new JTextArea();
private JTextArea jTextArea3 = new JTextArea();
private JComboBox JComboAuthorlist = new JComboBox();
private final String LABEL = "JLabel( )";
private final String BUTTON = "JButton";
private final String TEXTAREA = "JTextArea( )";
private final String TEXTFIELD = "JTextField( )";
private final String EMPTY = "";
private final Integer JSPLIT_DIV_LOC = 396;

public InsertModel() {
}

public void start_InsertModel() {
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().add(buildMainPanel(),BorderLayout.CENTER);

frame.getContentPane().add(buildStatusPanel(),BorderLayout.PAGE_END);

try { UIManager.setLookAndFeel( new
com.incors.plaf.kunststoff.KunststoffLookAndFeel());
} catch (Exception e) { }
SwingUtilities.updateComponentTreeUI(frame);

frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
InsertModel instance = new InsertModel();
instance.start_InsertModel();
}
protected JComponent buildMainPanel() {
JComponent topComponent = buildTopPanel();
JComponent botComponent = buildBottomPanel();

JSplitPane splitPane = new JSplitPane(
JSplitPane.VERTICAL_SPLIT,
true,
topComponent,botComponent);
splitPane.setDividerLocation(JSPLIT_DIV_LOC);
splitPane.setContinuousLayout(true);
splitPane.setBorder(Borders.DIALOG_BORDER);
splitPane.setOneTouchExpandable(true);
return splitPane;
}
private JComponent buildTopPanel() {
FormLayout layout = new FormLayout(
"12dlu, right:pref, 6dlu, 50dlu, 6dlu, 50dlu, 6dlu, " +
"right:35dlu, 6dlu, left:50dlu, 6dlu, right:50dlu," +
"6dlu, left:50dlu, 6dlu, fill:default:grow",
""); // add rows dynamically

DefaultFormBuilder builder = DEBUGMODE
? new DefaultFormBuilder(layout,new FormDebugPanel())
: new DefaultFormBuilder(layout);

builder.setDefaultDialogBorder();
builder.setRowGroupingEnabled(true);
builder.setLeadingColumnOffset(1);

CellConstraints cc = new CellConstraints();
builder.appendSeparator("Separator 1");
builder.append(LABEL,buildControl(jTextField1,TEXTFIELD),3);
builder.append(LABEL,buildControl(jLabel1,LABEL));
builder.append(LABEL,buildControl(jLabel2,LABEL));
builder.nextLine();
builder.append(LABEL,JComboAuthorlist,7);
builder.nextLine();
builder.appendSeparator("Separator 2");
builder.append(LABEL,buildControl(jTextField2,TEXTFIELD),3);
builder.append(LABEL,buildControl(jLabel3,LABEL));
builder.nextLine();
builder.append(LABEL,buildControl(jTextField3,TEXTFIELD),5);
builder.nextLine();
builder.append(LABEL,buildControl(jTextField4,TEXTFIELD),5);
builder.nextLine();
builder.append(LABEL,buildControl(jTextField5,TEXTFIELD),5);
builder.nextLine();
builder.append(LABEL,buildControl(jTextField6,TEXTFIELD),3);
builder.nextLine();
builder.append(LABEL,buildControl(jTextField7,TEXTFIELD));
builder.nextLine();
builder.append(LABEL,buildControl(jTextField8,TEXTFIELD),7);
builder.nextColumn(-2 );
builder.append(EMPTY,buildButton(BUTTON),1);

builder.appendRow(builder.getLineGapSpec());
builder.appendRow(new RowSpec("fill:41dlu:grow"));
builder.nextLine(2);
builder.append(LABEL);
builder.add(buildControl(jTextArea1,TEXTAREA),cc.xyw(builder
.getColumn(),builder.getRow(),13));
builder.appendRow(builder.getLineGapSpec());

if (DEBUGMODE) FormDebugUtils.dumpAll(builder.getPanel());

return builder.getPanel();
}
private JComponent buildBottomPanel(){
FormLayout layout = new FormLayout(
"12dlu, right:pref, 6dlu, default:grow",
"12dlu, pref, 3dlu, fill:0:grow(0.50), 3dlu," +
"fill:0:grow(0.50), 6dlu, 18dlu");

DefaultFormBuilder builder = DEBUGMODE
? new DefaultFormBuilder(layout,new FormDebugPanel())
: new DefaultFormBuilder(layout);

builder.setDefaultDialogBorder();
builder.setRowGroupingEnabled(true);
builder.setLeadingColumnOffset(1);

builder.appendSeparator("Separator 3");
builder.nextLine(3);
builder.append(LABEL,buildControl(jTextArea2,TEXTAREA));
builder.nextLine(2);
builder.append(LABEL,buildControl(jTextArea3,TEXTAREA));
builder.nextLine(2);
builder.nextColumn(2);


builder.append(ButtonBarFactory.buildCenteredBar(buildButton(BUTTON),buildButton(BUTTON)));

if (DEBUGMODE) FormDebugUtils.dumpAll(builder.getPanel());
return builder.getPanel();
}
private JComponent buildStatusPanel() {
jTextField9 = buildControl(jTextField9,TEXTFIELD);
jTextField9.setFont(new Font("Dialog",1,12));
jTextField9.setEditable(false);

jTextField9.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
FormLayout layout = new FormLayout("default:grow","");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
builder.append(jTextField9);
return builder.getPanel();
}

/*
-----------------------------------------------------------------------------------
* Controls Factories
*
-----------------------------------------------------------------------------------
*/
private JButton buildButton(String labelText){
JButton jButton = new JButton(labelText);
jButton.setName(labelText);
jButton.setActionCommand(labelText);
return jButton;
}
private JLabel buildControl(JLabel jLabel,String label) {
if (DEBUGMODE) jLabel.setText(label);

jLabel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
jLabel.setBackground(Color.black);
return jLabel;
}
private JTextField buildControl(JTextField jTextField,String label) {
if (DEBUGMODE) jTextField.setText(label);
jTextField.setName(label);
jTextField.setForeground(Color.white);
jTextField.setBackground(Color.red);

jTextField.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
jTextField.setDragEnabled(true);
return jTextField;
}
private JScrollPane buildControl(JTextArea jTextArea,String label)
{
if (DEBUGMODE) jTextArea.setText(label);
jTextArea.setName(label);
jTextArea.setForeground(Color.white);
jTextArea.setBackground(Color.blue);

jTextArea.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
jTextArea.setFont(new Font("Dialog",1,11));
jTextArea.setLineWrap(true);
jTextArea.setDragEnabled(true);
return new JScrollPane(jTextArea);
}
}

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
O

Oliver Wong

IchBin said:
No, actually they have a free version for their Forms, Looks, Animation,
Binding and Validation. The product, at cost, is their Swing Suite. All
come with extensive examples and api docs, even though freeware.

You can get the free libs at:
http://www.jgoodies.com/freeware

Thanks for the clarification. I guess I'll take another look at it over
the weekend perhaps.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top