Thread View: borland.public.jbuilder.java.swing
4 messages
4 total messages
Started by Oliver
Fri, 01 Apr 2005 14:26
JScrollPane for JTable in a GridBagLayout
Author: Oliver
Date: Fri, 01 Apr 2005 14:26
Date: Fri, 01 Apr 2005 14:26
24 lines
2047 bytes
2047 bytes
Hello, i am having some trouble in implementing a JScrollPane for a JTable (im showing database records there via SQL). The JScrollPane is placed on a JPanel which in turn resides on my main frame. My main Frame has a GridBagLayout.The JPanel has also a GridBagLayout. I am using table.setSize(...) to make the JTable bigger than the screen. This works ok. Now im using table.setPreferredScrollableViewportSize(t); where t is a region inside the screen (smaller than the JTable). Now: how big do i have to make the JScrollPane? 1) if i make the JScrollPane as big as the JTable, then there appears a horizontal ScrollBar (scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); but it has no knob for scrolling (i assume because they have the same size, the system thinks its not necessary) 2) if i make the JScrollPane as big as t (inside the screen), the JTable becomes also smaller (which i do not want - i want the JTable to be bigger than the screen). Does somebody have a hint how i can get a horizontal scrollbar which works for a JTable which is bigger than the screen? thanks Oliver
Re: JScrollPane for JTable in a GridBagLayout
Author: Oliver
Date: Fri, 01 Apr 2005 15:57
Date: Fri, 01 Apr 2005 15:57
15 lines
1309 bytes
1309 bytes
Hello, now i have tried the following approach: table.setAutoResizeMode (JTable.AUTO_RESIZE_OFF); scroller.setHorizontalScrollBar(new JScrollBar()); table.setAutoResizeMode (JTable.AUTO_RESIZE_OFF); this is almost ok (at least i can scroll the table now) - but it looks somewhat odd (i can scroll the table horizontally, but i have to pull the scrollbar up and down to do this). regards Oliver
Re: JScrollPane for JTable in a GridBagLayout
Author: John McGrath [TeamB]
Date: Sat, 02 Apr 2005 04:49
Date: Sat, 02 Apr 2005 04:49
22 lines
1641 bytes
1641 bytes
On 4/1/2005 at 9:26:20 AM, Oliver wrote:
> 1) if i make the JScrollPane as big as the JTable, then there appears a
> horizontal ScrollBar
> (scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_A
> LWAYS); but it has no knob for scrolling (i assume because they have the
> same size, the system thinks its not necessary)
>
> 2) if i make the JScrollPane as big as t (inside the screen), the JTable
> becomes also smaller (which i do not want - i want the JTable to be
> bigger than the screen).
Can you post a runnable example of the problem?
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: JScrollPane for JTable in a GridBagLayout
Author: Oliver
Date: Fri, 08 Apr 2005 10:10
Date: Fri, 08 Apr 2005 10:10
57 lines
3080 bytes
3080 bytes
Hello
its a bit difficult for me to extract the relevant parts from
my code, but i am using
protected ColorTable table = new ColorTable();
protected JScrollPane scroller = new JScrollPane(table);
private void createGUI() {
GridBagLayout layout = new GridBagLayout();
controlPanel.setLayout(layout);
controlPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEtchedBorder(),
BorderFactory.createEmptyBorder(10, 10, 10, 10)));
// controlPanel.setForeground();
setLayout(layout);
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.anchor = GridBagConstraints.NORTH;
constraints.weightx = 1;
constraints.weighty = 0;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 1;
add(toolBar, constraints);
toolBar.addSeparator(new Dimension(10, -1));
toolBar.setFloatable(false);
toolBar.setBackground(new Color(133,100,183));
constraints.gridy = 1;
add(controlPanel, constraints);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.CENTER;
constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridy = 2;
scroller.setBorder(BorderFactory.createLoweredBevelBorder());
add(scroller, constraints);
setPreferredSize(new Dimension(800, 800));
}
private void SetScrollbar() {
table.setAutoResizeMode (JTable.AUTO_RESIZE_OFF);
scroller.setHorizontalScrollBar(new JScrollBar());
table.setAutoResizeMode (JTable.AUTO_RESIZE_OFF);
}
where ColorTable is a descendant of JTable (with a special Renderer), and scroller is a JScrollPane.
Im not so familiar with the GridBagLayout, maybe this plays a role here too?
kind regards
Oliver
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads