3

I'm using Netbeans GUI Builder to create a GUI app (so all the code generated is by Netbeans).

Everything looks fine in the Preview Design, but when I run the app, the JScrollPane displays badly...

Default GUI

...as you can see, only half of the scrollbar is visible.

I have tried manually setting the JScrollBar for the JScrollPane, using my own method:

jScrollPane1.setVerticalScrollBar(getScrollBarForScrollPane());

But that gives this result...

New GUI

Maybe there is some property on the JScrollBar or JScrollPane that I need to change?

I have been researching this for ages, so am hoping someone has some suggestions! :)

Here is my entire code...

package uk.co.mobilewebexpert.myappmonitor;

import javax.swing.ImageIcon;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

public class MyAppMonitorJFrame extends javax.swing.JFrame {

    private final ImageIcon greenIcon = new ImageIcon(getClass().getResource("/green_light.jpg"));
    private final ImageIcon amberIcon = new ImageIcon(getClass().getResource("/amber_light.jpg"));
    private final ImageIcon redIcon = new ImageIcon(getClass().getResource("/red_light.jpg"));

    /**
     * Creates new form MyAppMonitorJFrame
     */
    public MyAppMonitorJFrame() {
        initComponents();

        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
        rightRenderer.setFont(new java.awt.Font("Tahoma", 1, 21));
        for (int i = 0; i < jTable1.getColumnCount(); i++) {
            jTable1.getColumn(jTable1.getColumnName(i)).setHeaderRenderer(rightRenderer);
            jTable1.getColumn(jTable1.getColumnName(i)).setCellRenderer(rightRenderer);

        }
        //jTable1.getTableHeader().setFont(new java.awt.Font("Tahoma", 1, 11));


        DefaultTableModel tableModel = (DefaultTableModel) jTable1.getModel();
        tableModel.addRow(new Object[]{greenIcon, "2", "3", "4", "5", "6", "7"});


        jScrollPane1.setInsets
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("MYOB");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Status Summary", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Total");
        jLabel6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/green_light_2.jpg"))); // NOI18N
        jLabel7.setText("Online");
        jLabel7.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/amber_light_2.jpg"))); // NOI18N
        jLabel8.setText("Suspect");
        jLabel8.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/red_light_2.jpg"))); // NOI18N
        jLabel9.setText("Offline");
        jLabel9.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("?");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("?");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("?");

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("?");

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 10, Short.MAX_VALUE))
            .addContainerGap()));
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
            .addComponent(jLabel6)
            .addComponent(jLabel7)
            .addComponent(jLabel8)
            .addComponent(jLabel9)
            .addComponent(jLabel10))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
            .addComponent(jLabel1)
            .addComponent(jLabel2)
            .addComponent(jLabel3)
            .addComponent(jLabel4)
            .addComponent(jLabel5))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jLabel11.setText("Enter device serial number");

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jButton1.setText("Go");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
            .addComponent(jLabel11)
            .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createSequentialGroup()
            .addComponent(jTextField1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jButton1)))
            .addContainerGap()));
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jLabel11)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jButton1))));

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Device Details", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        jScrollPane1.setVerticalScrollBar(getScrollBarForScrollPane());

        jTable1.setBackground(new java.awt.Color(254, 254, 254));
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object[][]{
            {null, null, null, null, null, null},
            {null, null, null, null, null, null},
            {null, null, null, null, null, null},
            {null, null, null, null, null, null},
            {null, null, null, null, null, null},
            {null, null, null, null, null, null},
            {null, null, null, null, null, null},
            {null, null, null, null, null, null},
            {null, null, null, null, null, null},
            {null, null, null, null, null, null}
        },
            new String[]{
            "Serial Number", "Device Name", "Status", "Current Uptime", "Current Downtime", "Last Known Uptime"
        }));
        jTable1.setGridColor(new java.awt.Color(254, 254, 254));
        jTable1.setShowHorizontalLines(false);
        jTable1.setShowVerticalLines(false);
        jScrollPane1.setViewportView(jTable1);

        jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Log", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        jScrollPane2.setViewportView(jTextPane1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(jScrollPane2))
            .addContainerGap()));
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
            .addContainerGap()));

        pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MyAppMonitorJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MyAppMonitorJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MyAppMonitorJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MyAppMonitorJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MyAppMonitorJFrame().setVisible(true);
            }
        });
    }

    public javax.swing.JScrollBar getScrollBarForScrollPane() {
        int width = 50; //set extremely large to exaggerate the issue
        javax.swing.JScrollBar jScrollBar = new javax.swing.JScrollBar(javax.swing.JScrollBar.VERTICAL);
        jScrollBar.setPreferredSize(new java.awt.Dimension(width, Integer.MAX_VALUE));
        return jScrollBar;
    }
// Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextPane jTextPane1;
// End of variables declaration
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
  • 3
    That's why I hate using GUI-designer for writing swing applications. – Eng.Fouad Feb 28 '13 at 19:22
  • I have tried building with JDK 1.6 and JDK 1.7 . – ban-geoengineering Feb 28 '13 at 19:22
  • Eng, I've found the GUI Builder to be really useful (much better than banging my head against the wall with layout managers), but it's just this particular problem which is getting me. – ban-geoengineering Feb 28 '13 at 19:23
  • @user What is the wrong with the first screen shot? I see the full scroll bar is shown –  Feb 28 '13 at 19:25
  • @user1617737 But it is really bad in terms of maintainability and code-readability, besides not understanding the swing well (specially if you want to customize the components). – Eng.Fouad Feb 28 '13 at 19:26
  • @Eng.Fouad I don't think so. If the GUI builder of NetBeans is not appreciated, you can try `JFromDesigner`. They actually save your time much times than manually writing a `Layout`-based design –  Feb 28 '13 at 19:27
  • @Eng.Fouad explain to me how this is an issue with using a form editor. The JScrollPane is a self contained component, it's scroll bars are managed by it internally – MadProgrammer Feb 28 '13 at 19:27
  • @MadProgrammer It's true that JScrollPane is a self contained component, but it is affected by the other components such as its parent container. – Eng.Fouad Feb 28 '13 at 19:30
  • @Eng.Fouad how are the scroll bars effected by anything outside the scroll pane? The are managed and laid out by the scroll pane, the only way I can see this effect being caused is if the scroll panes layout manager is changed (and I'm not sure if it can be) – MadProgrammer Feb 28 '13 at 19:32
  • @Desolator It saves me some time but I will lose other stuff as I said above. It is a trade-off. I think GUI-designer is suitable for mockups or small swing applications such as a small calculator. – Eng.Fouad Feb 28 '13 at 19:32
  • @Desolator The full length of the scrollbar is shown, but the left hand side of it has been clipped visually. – ban-geoengineering Feb 28 '13 at 19:34
  • @user1617737 try removing/resting the borders around the scroll panes to here defaults – MadProgrammer Feb 28 '13 at 19:34
  • @MadProgrammer, I've just been playing around with that, but all I've managed to do so far is make the scrollbar disappear - e.g., like with jScrollPane1.setBorder(null);. Can you recommend some code? – ban-geoengineering Feb 28 '13 at 19:37
  • @Eng.Fouad I'm working on a application with well over a million lines of code and use netbeans form designer as our primary entry point for most of our UI code. It's faster and simpler then hand coding much of the UI. Don't get me wrong, I do a lot if hand coded UI work as well, but when your trying to get a lay out cut out quickly, they are time saver. I agree, though, they re a tool and you should have a good understanding of how layout managers work in the first place. Plus, I never use GropuLayout, it goes wrong to way to quickly. After 12 years of UI coding, I have better things to ;) – MadProgrammer Feb 28 '13 at 19:38
  • @user1617737 don't set it to null, reset it. In netbeans right click the border property of the scroll pane a click rest default value – MadProgrammer Feb 28 '13 at 19:40
  • 1
    @user1617737: No, GUI Builder tools for Java are not accepted. It doesn't matter whether it is netbeans or something else. As you can already see, it is not supporting any good coding concepts. See how it calls components, each and every time it calls to the complete package! These GUI builders do follow group layout, which is not user friendly. Even researches clearly say this is one of worst practices. To be honest, this practice is rejected from GOOD java community. Java is differ from .NET, where this is acceptable, and that is one reason Java gained Honor among programmers than .NET – PeakGen Feb 28 '13 at 19:45
  • @Yohan WHERE IS THE PROBLEM? I cannot observe it. The builder seems to work fine –  Feb 28 '13 at 20:12
  • @Desolator: pardon me????? – PeakGen Feb 28 '13 at 20:17
  • @Yohan I don't see what is the wrong with the first screen shot. –  Feb 28 '13 at 20:21
  • @Desolator: ohh. There are only few can answer that. Since Java people are originally from hand code practice, this question will not suit to many. I didn't address any of the user's question, what I did is showing how bad the automated GUI build when it comes to Java. – PeakGen Feb 28 '13 at 20:24
  • @user1617737 The first screen shot is perfect. I don't see any problem and I think the question is meaningless –  Feb 28 '13 at 20:26
  • @Desolator The problem is that although the full length of the scrollbar is shown, the left hand side of it has been clipped visually. #attentiontodetail ! – ban-geoengineering Feb 28 '13 at 22:12
  • @user1617737 Finally got to run the code. The only time I get this problem is when I use you `getScrollBarForScrollPane`. If I remove it, it works fine – MadProgrammer Feb 28 '13 at 22:15
  • @MadProgrammer Not for me... – ban-geoengineering Feb 28 '13 at 22:20
  • @user1617737 It's the only thing I changed. With it, the scroll bar is to wide, without, it's fine... – MadProgrammer Feb 28 '13 at 22:21
  • @MadProgrammer Looks like I'm a bit behind the times when it comes to how I expect scrollbars to look. Thanks for your help. – ban-geoengineering Feb 28 '13 at 22:27

2 Answers2

1

As you can see in this snapshot from the reference, your scroll bar is perfect: enter image description here

Aubin
  • 14,617
  • 9
  • 61
  • 84
  • 2
    How does this answer the question? –  Feb 28 '13 at 19:41
  • The question is a nonsense: the scrollbar IS well drawn. No solution exists for problem which isn't. – Aubin Feb 28 '13 at 19:42
  • 1
    The question was "...p, the JScrollPane displays badly...". It's not true, the JScrollPane is perfectly displayed. – Aubin Feb 28 '13 at 19:57
  • @Aubin yes there are a few issues, I'm tried to describe only about important ... – mKorbel Feb 28 '13 at 20:22
  • 1
    Thanks for this. The scrollbar just looks wrong, like the left hand part of it is missing. Not seen a scrollbar like this before and it doesn't look like this in the Preview Design tool either so I presumed it was a bug. – ban-geoengineering Feb 28 '13 at 22:25
  • I've found the real cause of this issue now. Check out the javax.swing.UIManager.setLookAndFeel(info.getClassName()); line in the source code - that is what (in my opinion) is resulting in such a naff scrollbar. – ban-geoengineering Mar 04 '13 at 12:04
  • With reference to the source code, I have commented out that entire block of code and it looks normal again. Can also change "Nimbus" to "Metal", "CDE/Motif", "Windows" or "Windows Classic"... – ban-geoengineering Mar 04 '13 at 12:07
1
  1. Swing GUI is correctly builded, meaning methods and code generated by GUI_Builer :-),

  2. one of issues is generated from code line tableModel.addRow(new Object[]{greenIcon, "2", "3", "4", "5", "6", "7"});

  3. you added a new row to the JTable, to the Swing GUI, after is called pack() last code line pack(); in initComponents();,

  4. but major issue is that PreferredSize is calculated internally from code line .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE), then override this size by using quite proper method jTable1.setPreferredScrollableViewportSize(jTable1.getPreferredSize()); is quite pretty ignored

  5. write this code by hand

mKorbel
  • 109,525
  • 20
  • 134
  • 319