I've to upgrade project to Java 8. After running my application, scroll from JScrollPane doesn't show. Same piece of code works in Java 7 and everything is ok.
public static void main(String[] a){
JPanel contentPane = new JPanel();
contentPane.setBackground(Color.WHITE);
contentPane.setBorder(new EmptyBorder(0, 0, 0, 0));
contentPane.setLayout(new javax.swing.BoxLayout(contentPane, javax.swing.BoxLayout.Y_AXIS));
JPanel aggregates = new JPanel("Aggregates", new Insets(40, 0, 0, 0));
GridBagConstraints gbc_aggregates = new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, 1, new Insets(10, 10, 10, 10), 0, 0);
gbl_panel.setConstraints(aggregates, gbc_aggregates);
GridBagLayout gbl_agregats = new GridBagLayout();
addParametersLayout(gbl_agregats, new int[]{0,0,0}, new int[]{0, 0},new double[]{ 0.0, 0.0, Double.MIN_VALUE}, new double[]{0.0, Double.MIN_VALUE} );
aggregates.setLayout(gbl_agregats);
JTable table = new JTable(new MyTableModel(null));
table.setPreferredSize(new Dimension(850, Const.rowHeight));
JScrollPane scrollPane = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(850, 10 *Const.rowHeight));
GridBagConstraints gbc_scrollPane= new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, 1, new Insets(5, 5, 20, 5), 0, 0);
gbl_agregats.setConstraints(scrollPane, gbc_scrollPane);
aggregates.add(scrollPane);
JPanel main_panel = new JPanel();
main_panel.add(aggregates);
JScrollPane scrPane = new JScrollPane(main_panel);
scrPane.getVerticalScrollBar().setUnitIncrement(16);
scrPane.setBorder(BorderFactory.createEmptyBorder());
scrPane.getInsets().set(0, 0, 0, 0);
contentPane.add(scrPane);
setContentPane(contentPane);
}
public static void addParametersLayout(GridBagLayout gbl,
int[] columnWidths, int[] rowHeights, double[] columnWeights,
double[] rowWeights) {
gbl.columnWidths = columnWidths;
gbl.rowHeights = rowHeights;
gbl.columnWeights = columnWeights;
gbl.rowWeights = rowWeights;
}
Question: What was changed in Java 8 ? Why same scroll looks ok in older Java version ?
Edited:
Maybe i'm not too specific. When i compile my project i see something like that (just bar):
I can scroll my table because it's working, but it's invisible (i see just a bar).
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.LayoutManager;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTab
import javax.swing.border.EmptyBorder;
public class source8 {
public static void main(String[] a){
JPanel contentPane = new JPanel();
contentPane.setBackground(Color.WHITE);
contentPane.setBorder(new EmptyBorder(0, 0, 0, 0));
contentPane.setLayout(new javax.swing.BoxLayout(contentPane,
javax.swing.BoxLayout.Y_AXIS));
JPanel aggregates = new JPanel((LayoutManager) new Insets(40, 0,0,
0));
GridBagConstraints gbc_aggregates = new GridBagConstraints(0, 2,
1, 1, 0.0, 0.0, GridBagConstraints.WEST, 1, new Insets(10, 10, 10,
10), 0, 0);
GridBagLayout gbl_panel = new GridBagLayout();
gbl_panel.setConstraints(aggregates, gbc_aggregates);
GridBagLayout gbl_agregats = new GridBagLayout();
addParametersLayout(gbl_agregats, new int[]{0,0,0}, new int[]{0,
0},new double[]{ 0.0, 0.0, Double.MIN_VALUE}, new double[]{0.0,
Double.MIN_VALUE} );
aggregates.setLayout(gbl_agregats);
JTable table = new JTable(new MyTableModel(null));
table.setPreferredSize(new Dimension(850, Const.rowHeight));
JScrollPane scrollPane = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(850, 10
*Const.rowHeight));
GridBagConstraints gbc_scrollPane= new GridBagConstraints(0, 1, 3,
1, 0.0, 0.0, GridBagConstraints.WEST, 1, new Insets(5, 5, 20, 5),
0, 0);
gbl_agregats.setConstraints(scrollPane, gbc_scrollPane);
aggregates.add(scrollPane);
JPanel main_panel = new JPanel();
main_panel.add(aggregates);
JScrollPane scrPane = new JScrollPane(main_panel);
scrPane.getVerticalScrollBar().setUnitIncrement(16);
scrPane.setBorder(BorderFactory.createEmptyBorder());
scrPane.getInsets().set(0, 0, 0, 0);
contentPane.add(scrPane);
setContentPane(contentPane);
}
public static void addParametersLayout(GridBagLayout gbl,
int[] columnWidths, int[] rowHeights, double[] columnWeights,
double[] rowWeights) {
gbl.columnWidths = columnWidths;
gbl.rowHeights = rowHeights;
gbl.columnWeights = columnWeights;
gbl.rowWeights = rowWeights;
}
private static void setContentPane(JPanel contentPane) {
throw new UnsupportedOperationException("Not supported yet.");
//To change body of generated methods, choose Tools | Templates.
}
}
some change in code hope it works for you §§thanks
If anyone has the same problem. I added default ScrollBar size for my LookAndFeel and it works.
UIDefaults defaults = UIManager.getLookAndFeel().getDefaults();
defaults.put("ScrollBar.minimumThumbSize", new Dimension(30, 30));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.