Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4188905

JSplitPane.setDividerLocation(double) does not work with nested JSplitPane.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs



      Name: rk38400 Date: 11/10/98


      The following code demonstrates maximizing each component of split pane.
      This example contains one parent JSplitPane.
      Left and right component of parent split pane are also JSplitPane which contains TestCanvas.

       From menu you can selecte which component you want to maximize.

      To maximize selected component, I set divider location of parent split pane then child splipt pane.
      However, it sometimes did not work out.

      You can produce a bug by following steps.

      1. run source code.
      2. maximize either 1st or 2nd component which is contained by Left split pane.
      3. try to maximize 3rd component.
      It will maximize 4th component instead of 3rd component.



      /*********** source code **********/

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      public class TestFrame extends JFrame implements ActionListener {
      private JSplitPane mainSplitPane, leftSplitPane, rightSplitPane;

      public TestFrame() {

      JMenuBar menuBar = new JMenuBar();
      JMenu menu = new JMenu("Full Screen");

      JMenuItem menuItem = new JMenuItem("1st Screen");
      menuItem.addActionListener(this);
      menuItem.setActionCommand("1st");
      menu.add(menuItem);

      menuItem = new JMenuItem("2nd Screen");
      menuItem.addActionListener(this);
      menuItem.setActionCommand("2nd");
      menu.add(menuItem);

      menuItem = new JMenuItem("3rd Screen");
      menuItem.addActionListener(this);
      menuItem.setActionCommand("3rd");
      menu.add(menuItem);

      menuItem = new JMenuItem("4th Screen");
      menuItem.addActionListener(this);
      menuItem.setActionCommand("4th");
      menu.add(menuItem);

      menuBar.add(menu);
      setJMenuBar(menuBar);

      leftSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, new TestCanvas("1st screen"), new TestCanvas("2nd screen"));
      rightSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, new TestCanvas("3rd screen"), new TestCanvas("4th screen"));
      mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftSplitPane, rightSplitPane);
      getContentPane().add(mainSplitPane);

      Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
      setBounds(((int) d.width / 2 - 300),((int) d.height / 2 - 240),600,480);
      setVisible(true);

      addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
      System.exit(0);
      }
      });
      }

      public void actionPerformed(ActionEvent e) {
      String command = e.getActionCommand();
      if (command.equals("1st")) {
      mainSplitPane.setDividerLocation(1.0);
      leftSplitPane.setDividerLocation(1.0);
      }
      else if (command.equals("2nd")) {
      mainSplitPane.setDividerLocation(1.0);
      leftSplitPane.setDividerLocation(0.0);
      }
      else if (command.equals("3rd")) {
      mainSplitPane.setDividerLocation(0.0);
      rightSplitPane.setDividerLocation(1.0);
      //rightSplitPane.setDividerLocatoni(1000)
      }
      else if (command.equals("4th")) {
      mainSplitPane.setDividerLocation(0.0);
      rightSplitPane.setDividerLocation(0.0);
      }
      }

      class TestCanvas extends JPanel {
      private String name;

      public TestCanvas(String name) {
      if (name != null)
      this.name = name;
      else
      this.name = "test";
      setMinimumSize(new Dimension(0,0));
      }

      public void paint(Graphics g) {
      Rectangle paintBounds = g.getClipBounds();
      int height = paintBounds.y + paintBounds.height;
      int width = paintBounds.x + paintBounds.width;
      g.setFont(new Font("Helvetica", Font.BOLD, 48));
      g.setColor(Color.lightGray.brighter());
      FontMetrics fontMetrics = g.getFontMetrics();
      for (int y = fontMetrics.getHeight(); y<height; y+=fontMetrics.getHeight()+10) {
      for (int x = 10; x < width; x+= fontMetrics.stringWidth(name) + 10) {
      g.drawString(name, x,y);
      }
      }
      }
      }

      public static void main(String argv[]) {
      new TestFrame();
      }
      }
      (Review ID: 42081)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            rkarsunw Ralph Kar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: