0

Hi, I am making a program that has a JSplitPane and its background is transparent so I add two panels with a JScrollPane on the JSplitPane.. when I add the contents in the panel it doesn't appear.

This is the code that I was using:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JViewport;
import javax.swing.UIManager;
public class sample {
JFrame mainFrame;
JPanel mainPanel;
JPanel splitPaneLeftPanel;
JPanel splitPaneRightPanel;
JSplitPane splitPane;
JScrollPane rightPanelScroll;
JScrollPane leftPanelScroll;
JViewport viewport;
sample(){
    Frame();
    SplitPaneAndContent();
    mainFrame.setVisible(true);
     }
 public void Frame(){
        mainFrame = new JFrame();
        mainFrame.setTitle("Sample");
        mainFrame.setLayout(new BorderLayout());
        mainFrame.setSize(1024,720);
        mainFrame.setMaximumSize(new Dimension(1366,768));
        mainFrame.setMinimumSize(new Dimension(800,600));
        mainFrame.setResizable(true);
        mainFrame.setLocationRelativeTo(null);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

 public void SplitPaneAndContent(){
     mainPanel = new JPanel(new BorderLayout());
     splitPaneLeftPanel = new JPanel(new BorderLayout());
     splitPaneRightPanel = new JPanel(new BorderLayout());
     mainPanel.setBackground(Color.blue);
     JScrollPane rightPanelScroll = new JScrollPane(splitPaneRightPanel);
     JScrollPane LeftPanelScroll = new JScrollPane(splitPaneLeftPanel);
    viewport = new JViewport();
    rightPanelScroll.setViewport(viewport);
    rightPanelScroll.getViewport().setOpaque(false);
    JLabel Text = new JLabel("SAMPLE");
    Text.setBackground(Color.red);

    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,LeftPanelScroll,rightPanelScroll);
    splitPane.setDividerLocation(300);

    splitPaneLeftPanel.setOpaque(false);
    splitPaneRightPanel.setOpaque(false);
    rightPanelScroll.setOpaque(false);
    splitPane.setOpaque(false);

     splitPaneRightPanel.add(Text, BorderLayout.CENTER);
     mainPanel.add(splitPane, BorderLayout.CENTER);
     mainFrame.add(mainPanel, BorderLayout.CENTER);
 }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            new sample();
        } 
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
2
Contributors
1
Reply
8
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

The declarations on 42/43 hide the variables declared on lines 17/18 - probably not causing trouble in this case, but a bad idea anyway.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.