Home » Java » jpanel – Java JScrollpane with background set as setBackground(new Color(0,0,0,122)); glitch-Exceptionshub

jpanel – Java JScrollpane with background set as setBackground(new Color(0,0,0,122)); glitch-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Hi I have a JScrollPane on top of a JPanel in which that JPanel is on a JTabbedPane as shown in the image below that is fine when I first enter into the Dashboard Tab and don’t scroll but once I scroll down the then the background gives off a complete black background with blurry texts.

Normal JScrollPane

Glitched JScrollPane

My code for the JScrollPane

GridBagConstraints d = new GridBagConstraints();
JScrollPane dashboardSavedTasksScrollPane;
JPanel dashboardSavedTasks  = new JPanel(false);
        d.fill = GridBagConstraints.BOTH;

        MainPanel.setBackground(new Color(0,0,0,122));

        dashboardSavedTasks.setLayout(new GridBagLayout());
        dashboardSavedTasks.setSize(1280,612); 
        dashboardSavedTasks.setPreferredSize(new Dimension(1280,612));
        //dashboardSavedTasks.setPreferredSize(preferredSize);
        dashboardSavedTasks.setLocation(0,30);
        dashboardSavedTasks.setOpaque(false);
        //dashboardSavedTasks.setBackground(new Color(0,0,0,122));

        //dashboardSavedTasks.add(dashboardSavedTasks,gbcForSavedTasksPanel);

        dashboardSavedTasksScrollPane = new JScrollPane(dashboardSavedTasks);

        //dashboardSavedTasks.setBorder(BorderFactory.createLineBorder(Color.magenta));
        //dashboardSavedTasksScrollPane.setLayout(new GridBagLayout());
        dashboardSavedTasksScrollPane.getViewport().setPreferredSize(new Dimension(1280,100));
        //dashboardSavedTasksScrollPane.setPreferredSize(new Dimension(1920,880));
        dashboardSavedTasksScrollPane.setLocation(0,30);
        dashboardSavedTasksScrollPane.setSize(1280,612);
        dashboardSavedTasksScrollPane.setPreferredSize(new Dimension(1280,612));

        //dashboardSavedTasksScrollPane.setVisible(true);
        dashboardSavedTasksScrollPane.setViewportView(dashboardSavedTasks);
        dashboardSavedTasksScrollPane.setOpaque(false);
        dashboardSavedTasksScrollPane.getViewport().setOpaque(false);
        dashboardSavedTasksScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        dashboardSavedTasksScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        //dashboardSavedTasksScrollPane.setBackground(new Color(0,0,0,122));
        //dashboardSavedTasksScrollPane.getViewport().setBackground(new Color(0,0,0,122));
        d.gridx = 0;
        d.gridy = 0;
        d.weighty = 1;
        d.weightx = 1;

        MainPanel.add(dashboardSavedTasksScrollPane,d);
How to&Answers: