I'm pretty new to java but have lots of coding experience with ruby, c and gui with gtk2 and qt. I'm trying to understand (and get rid of) the dead space to the far left portion of the window. The split panes have white backgrounds to separate it from the "dead zone". This dead area also seems to grow proportionally when the window is maximized.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.io.*;

public class MainFrame extends JPanel {
    private JSplitPane splitPane1;
    private	JSplitPane splitPane2;
	
    private JPanel Panel2;
    private JPanel Panel3;
    private JPanel Panel1;
    private JFrame frame;
    private Font font;
    
    MainFrame(JFrame iframe,
	             Container container) {
        frame  = iframe;
	container.setLayout(new  BoxLayout(container,BoxLayout.Y_AXIS));
    splitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
		splitPane1.setPreferredSize(new Dimension(1100,800));
    splitPane1.setOneTouchExpandable(true);
    splitPane1.setDividerLocation(0.9);
    splitPane2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane2.setOneTouchExpandable(true);
    splitPane2.setDividerLocation(0.5);
		font = new Font("Monospaced",Font.BOLD,14); 

    Panel2 = new JPanel();
		Panel2.setBackground(Color.white); 
		Panel3 = new JPanel();
		Panel3.setBackground(Color.white); 
		Panel1 = new JPanel();
		Panel1.setBackground(Color.white); 
		
		splitPane1.setResizeWeight(0.9);
		splitPane2.setResizeWeight(0.5);

		splitPane1.add(splitPane2);
		splitPane1.add(Panel2);
		splitPane2.add(Panel3);
		splitPane2.add(Panel1);
		splitPane1.setVisible(true);
		splitPane2.setVisible(true);
		container.add(splitPane1);
  }
		
  public static void main(String args[]) {
		
    JFrame frame = new JFrame("Title for Window");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
    Container container = frame.getContentPane();
		
    MainFrame mf = new MainFrame(frame,container);
    frame.add(mf);
    frame.pack();
    frame.setSize(1100,800);
		frame.validate();
    frame.setVisible(true);
  }
}

You're adding your components to the frame content pane itself - not the JPanel that you're constructing. So you end up with an empty panel plus your splitpane. You just need alter two lines to fix that

frame = iframe;
        // you want to set the panel layout and pass it as ref instead of 'container'
        [B]setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));[/B]
        splitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        splitPane1.setPreferredSize(new Dimension(1100, 800));
        splitPane1.setOneTouchExpandable(true);
        splitPane1.setDividerLocation(0.9);
        splitPane2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        splitPane2.setOneTouchExpandable(true);
        splitPane2.setDividerLocation(0.5);
        font = new Font("Monospaced", Font.BOLD, 14);

        Panel2 = new JPanel();
        Panel2.setBackground(Color.white);
        Panel3 = new JPanel();
        Panel3.setBackground(Color.white);
        Panel1 = new JPanel();
        Panel1.setBackground(Color.white);

        splitPane1.setResizeWeight(0.9);
        splitPane2.setResizeWeight(0.5);

        splitPane1.add(splitPane2);
        splitPane1.add(Panel2);
        splitPane2.add(Panel3);
        splitPane2.add(Panel1);
        splitPane1.setVisible(true);
        splitPane2.setVisible(true);
        // add to panel - not 'container'
        [B]add(splitPane1);[/B]

edit: I really don't see any use for the "container" parameter at all. It's redundant with the frame reference and depending on what else you plan to do with the code you may not even need the frame reference.

Thanks! A quick and simple response! Excellent!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.