Article View: borland.public.jbuilder.java.swing
Article #476Client fills entire JScrollPane, I do NOT want this.
From: chocawok
Date: Sat, 16 Jul 2005 02:16
Date: Sat, 16 Jul 2005 02:16
96 lines
4088 bytes
4088 bytes
Hi, I'm trying to create a "tiling" application.
I have a JPanel with a grid layout. Currently it has 3 rows and 3
columns.
I put a jlabel into each "cell". The jlabel is set to be 50 high by 50
wide.
When however I put this Jlabel into the Jscrollpane , my prefered size
for
the Jlabels is ignored and the grow so that the Jpanel fills the entire
Scrollpane viewport!
How do i get it so that this does not happen. I want my Jlabels to stay
the
size i want, and to be bunched up in the top left corner of the
Jscrollpane.
Any ideas??
P.S. I also want to dynamically resize this JPanel, and if it is
larger
than the scrollpanes viewport obviously I want it to scroll. This part
I'm
pretty sure I know how to do (delete the old Jpanel then create a new
of the
appropriate number of rows/cols, then add it to the Jscollpane).
Here is the code for the JPanel derived component (if you look you will
see
that i actually add the MapPanel component to a vanilla Jpanle with a
gridbad layout. This was an attempt to solve the problem, but only half
worked - i could get the right size vertically or horizontally but not
both)
----------------------------------------
public class MapPanel
extends JPanel {
int rows = 3;
int columns = 3;
GridLayout gridLayout1 = new GridLayout();
public MapPanel() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(gridLayout1);
gridLayout1.setColumns(columns);
gridLayout1.setRows(rows);
for (int row=0; row<rows; row++)
for (int column=0; column<columns; column++)
{
JLabel tempJLabel = new JLabel(Integer.toString(row));
tempJLabel.setBorder(BorderFactory.createEtchedBorder());
tempJLabel.setMaximumSize(new Dimension(50, 50));
tempJLabel.setMinimumSize(new Dimension(50, 50));
tempJLabel.setPreferredSize(new Dimension(50, 50));
this.add(tempJLabel);
}
this.setMaximumSize(new Dimension(rows * 50, columns * 50));
this.setMinimumSize(new Dimension(rows * 50, columns * 50));
this.setPreferredSize(new Dimension(rows * 50, columns * 50));
}
}
--------------------------------------
Here is where I add it to the scrollpane
JScrollPane jScrollPane1 = new JScrollPane();
JPanel SuperMapPanel = new JPanel();
GridLayout gridLayout1 = new GridLayout();
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.
HORIZONTAL_SCROLLBAR_AS_NEEDED);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
jScrollPane1.setBorder(BorderFactory.createEtchedBorder());
jScrollPane1.setPreferredSize(new Dimension(600, 480));
SuperMapPanel.setLayout(gridLayout1);
gridLayout1.setColumns(2);
gridLayout1.setRows(2);
SuperMapPanel.add(new MapPanel());//djw hand added code
jScrollPane1.getViewport().add(SuperMapPanel);
-----------------------------------------------------
Technical Details
Message-ID:
<1121480160.270587.24240@g43g2000cwa.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g43g2000cwa.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 111d45,f2514735a29dd257,start X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g43g2000cwa.googlegroups.com!not-for-mail From: "chocawok" <deanjamesware2@gmail.com> Newsgroups: borland.public.jbuilder.java.swing Subject: Client fills entire JScrollPane, I do NOT want this. Date: 15 Jul 2005 19:16:00 -0700 Organization: http://groups.google.com Lines: 97 Message-ID: <1121480160.270587.24240@g43g2000cwa.googlegroups.com> NNTP-Posting-Host: 84.9.53.129 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1121480172 30149 127.0.0.1 (16 Jul 2005 02:16:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 16 Jul 2005 02:16:12 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: g43g2000cwa.googlegroups.com; posting-host=84.9.53.129; posting-account=8lDJlg0AAACSFoZvqKe839QgJ31kTV-r