Center the JSplitPane divider inside a Jframe.

I am trying to use the JSplitPane class. I want to set the divider in the middle of the Jframe it is in. I have size the Jframe to 500,500 and set the divider to 250. The problem is if you include the title bar of the Jframe then it looks like it is in the right spot but I don�t want to include the title bar I just want the internal part of the frame to be divided in half not the whole Jframe. Any suggestion on how to do that? Also how do you keep the divider in the center when the Jframe is resized. Thanks.

setDividerLocation(0.5d) should do the job. if you want to set this in the constructor of your container, you should do this after everything else is done, somethinglike
SwingUtilities.invokeLater(new Runnable()
public void run()
xxx.setDividerLocation(0.5d);
});

Similar Messages

  • JSplitPane Divider problem...

    I'm having problem with the JSplitPane divider. Ive learned that the MouseListener class is most likely the reason why the divider isn't performing as expected. I had to learn how to use the MouseListener interface and I've also learned that the divider is an instance of BasicSplitPaneDivider. I've finally got the divider to PARTIALLY work if I only set the following:
    1) setting the setContinuousLayout(true)
    //setting it to false wont work for some reason, I want to fix that, too. By setting it to false, the divider wont move :(.
    and
    2) if I move the mouse slowly, so the divider can follow the mouse. If I move my mouse too fast, then my divider will suddenly stop the moment the mouse cursor hovers away from the divider.
    Can anyone help me fix the divider problem? Thanks in advance! Here's my code below:
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import java.awt.event.MouseEvent;
    import javax.swing.event.MouseInputAdapter;
    import javax.swing.plaf.basic.BasicSplitPaneDivider;
    public class JSplitPaneDemo{
         public static void main(String args[]){
              //Practice p = new Practice("SplitPane Divider Works Now?");
              JSplitPaneDemo x = new JSplitPaneDemo();
              x.new Practice("SplitPane Divider Works Now?");
         public class DendrogramListener extends MouseInputAdapter
              Container contentPane;
              Component button1, button2, button3;
              JSplitPane splitter;
              Point mLocation;
              JFrame myFrame;
              MyGlassPane glass;
              private boolean inDrag = false;
              private boolean inButton = false;
              private boolean inDivider = false;
              public DendrogramListener(JFrame frame)
                   this.myFrame = frame;
                   this.contentPane = frame.getContentPane();
                   this.mLocation = new Point();
              public DendrogramListener(AbstractButton aButton, AbstractButton b2, AbstractButton b3, MyGlassPane glass1, Container cP, JSplitPane split){
                   this.button1 = aButton;
                   this.button2 = b2;
                   this.button3 = b3;
                   this.glass = glass1;
                   this.contentPane = cP;
                   this.mLocation = new Point();
                   this.splitter = split;
              public void mouseDragged(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void mouseMoved(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void mouseClicked(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void mousePressed(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void mouseReleased(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
                   inDrag = false;
              public void mouseEntered(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void mouseExited(MouseEvent arg0) {
                   // TODO Auto-generated method stub
                   redispatchMouseEvent(arg0);
              public void redispatchMouseEvent(MouseEvent e){
                   inButton = false;
                   inDrag = false;
                   inDivider = false;
                   Component component = null;
                   JButton tempButton;
                   Container container = contentPane;
                   Point glassPanePoint = e.getPoint();
                   mLocation = e.getPoint();
                   Point containerPoint = SwingUtilities.convertPoint(glass, glassPanePoint, contentPane);
                   int eventID = e.getID();
                 component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y);
                 if (component == null) {
                      //System.out.println("NULL");
                     return;
                 if (component instanceof JButton) {
                     inButton = true;
                 if(component instanceof BasicSplitPaneDivider){
                      inDivider = true;
                      testForDrag(eventID);
                 if (inButton || inDivider)
                           Point componentPoint = SwingUtilities.convertPoint(glass, glassPanePoint, component);
                          component.dispatchEvent(new MouseEvent(component,
                                                               eventID,
                                                               e.getWhen(),
                                                               e.getModifiers(),
                                                               componentPoint.x,
                                                               componentPoint.y,
                                                               e.getClickCount(),
                                                               e.isPopupTrigger()));
                   testForDrag(eventID);
             private void testForDrag(int eventID) {
                 if (eventID == MouseEvent.MOUSE_PRESSED) {
                     inDrag = true;
         public class MyGlassPane extends JComponent {
              int x0, y0;
              Point mLocation;
              public MyGlassPane(AbstractButton aButton, AbstractButton b2, AbstractButton b3, Container cP, JSplitPane splitter){
                   DendrogramListener dl = new DendrogramListener(aButton, b2, b3, this, cP, splitter);
                   addMouseListener(dl);
                   addMouseMotionListener(dl);
             public void setPoint(Point p) {
                 mLocation = p;
         public class Practice extends JFrame implements ActionListener
              private MyGlassPane glassPane;
              public Practice(String str)
                   super(str);
                   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   setDefaultLookAndFeelDecorated(true);
                   addComponents(this);
                   pack();
                   setVisible(true);
              public Practice addComponents(final Practice p)
                   JPanel leftPane = new JPanel();
                   JPanel midPane = new JPanel();
                   JPanel rightPane = new JPanel();
                   JLabel l1 = new JLabel("Left panel");
                   JLabel r1 = new JLabel("Right panel");
                   JLabel m1 = new JLabel("Middle panel");
                   JButton b1 = new JButton("Button 1");
                   JButton b2 = new JButton("Button 2");
                   JButton b3 = new JButton("Button 3");
                   leftPane.add(l1);
                   leftPane.add(b3);
                   b3.setActionCommand("b3");
                   b3.addActionListener(this);
                   leftPane.setPreferredSize(new Dimension(200, 300));
                   midPane.add(m1);
                   midPane.add(b1);
                   midPane.setPreferredSize(new Dimension(200, 300));
                   rightPane.add(r1);
                   rightPane.add(b2);
                   rightPane.setPreferredSize(new Dimension(200, 300));
                   JSplitPane splitter2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, rightPane, midPane);
                   splitter2.setOneTouchExpandable(true);
                   splitter2.setContinuousLayout(true);
                   JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, splitter2);
                   splitter.setOneTouchExpandable(true);
                   splitter.setContinuousLayout(true);
                   getContentPane().add(splitter);
                   glassPane = new MyGlassPane(b1, b2, b3, p.getContentPane(), splitter);
                   this.setGlassPane(glassPane);
                   glassPane.setVisible(true);
                   return p;
              public void actionPerformed(ActionEvent arg0) {
                   // TODO Auto-generated method stub
                   if("b3".equals(arg0.getActionCommand())){
                        JOptionPane.showMessageDialog(this, "Button 3 Pressed!");
    }

    The problem with your listener is that you are only dispatching events to the
    button or divider when the mouse is directly over that component. This results
    in the behavior you see with the divider: you have to move the mouse slowly
    to keep it over the divider otherwise it gets over some other component and
    you stop dispatching the events to it.
    You actually have a similar problem with the buttons: if you click on one, it
    gets the event but if you then drag the mouse out of the button and release
    the mouse, it still triggers the button! This is not how buttons work: if you
    release the mouse when it is not over the button, it shouldn't trigger.
    Try this for your listener:
         public class DendrogramListener extends MouseInputAdapter {
              Component redispatch;
              boolean inside;
              Container contentPane;
              Component button1, button2, button3;
              JSplitPane splitter;
              Point mLocation;
              JFrame myFrame;
              MyGlassPane glass;
              private boolean inDrag = false;
              private boolean inButton = false;
              public DendrogramListener( JFrame frame ) {
                   this.myFrame = frame;
                   this.contentPane = frame.getContentPane();
                   this.mLocation = new Point();
              public DendrogramListener( AbstractButton aButton, AbstractButton b2,
                        AbstractButton b3, MyGlassPane glass1, Container cP,
                        JSplitPane split ) {
                   this.button1 = aButton;
                   this.button2 = b2;
                   this.button3 = b3;
                   this.glass = glass1;
                   this.contentPane = cP;
                   this.mLocation = new Point();
                   this.splitter = split;
              public void mouseDragged( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void mouseMoved( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void mouseClicked( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void mousePressed( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void mouseReleased( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
                   inDrag = false;
                   inButton = false;
              public void mouseEntered( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void mouseExited( MouseEvent arg0 ) {
                   redispatchMouseEvent( arg0 );
              public void redispatchMouseEvent( MouseEvent e ) {
                   int eventID = e.getID();
                   Point glassPanePoint = e.getPoint();
                   Point containerPoint = SwingUtilities.convertPoint( glass, glassPanePoint, contentPane );
                   if ( !inDrag && !inButton && eventID == MouseEvent.MOUSE_PRESSED ) {
                        redispatch = SwingUtilities.getDeepestComponentAt( contentPane, containerPoint.x, containerPoint.y );
                        inButton = ( redispatch instanceof JButton );
                        inside = inButton;
                        if ( !inButton )
                             inDrag = ( redispatch instanceof BasicSplitPaneDivider );
                   if ( inButton || inDrag ) {
                        if ( inButton )
                             eventID = possiblySwitchEventID( eventID, containerPoint );
                        Point componentPoint = SwingUtilities.convertPoint( glass, glassPanePoint, redispatch );
                        redispatch.dispatchEvent( new MouseEvent( redispatch, eventID, e.getWhen(), e.getModifiers(),
                                  componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger() ) );
              private int possiblySwitchEventID( int eventID, Point containerPoint ) {
                   int switchedID = eventID;
                   Component deepest = SwingUtilities.getDeepestComponentAt( contentPane, containerPoint.x, containerPoint.y );
                   if ( deepest == redispatch ) {
                        if ( ! inside )
                             switchedID = MouseEvent.MOUSE_ENTERED;
                        inside = true;
                   } else {
                        if ( inside )
                             switchedID = MouseEvent.MOUSE_EXITED;
                        inside = false;
                   return switchedID;
         }: jay

  • Another JSplitPane divider cursor problem

    I have the same problem discussed elsewhere in that the cursor doesn't change to a E_RESIZE_CURSOR when it's over a split panel divider. The code is in a large application too huge to post, and my attempts to simplify it have been unable to reproduce the problem. I have implemented the solution suggested in [http://forums.sun.com/thread.jspa?forumID=57&threadID=642994] but, although the mouse listener methods are indeed called, the cursor doesn't change. I have also tried calling setCursor on the parent of the JSplitPane, and on the JRootPane, but it doesn't change. In each case the mouse listener is called but the setCursor call has no effect.
    All the discussions on setCursor having no effect I've found are specific to JDialog. In my case, I have a deep window stack starting with JFrame, JRootPane, JLayeredPane, down through several JPanels, a JSplitPane, more JPanels, my JSplitPane, which contains 2 JPanels, and so on.
    What would prevent the JSplitPane divider from changing the cursor itself? Assuming it's trying, just as my explicit mouse listener is, what could be overriding, obscuring, or intercepting my cursor change?
    Any help would be most welcome
    Thanks!

    I have the same problem discussed elsewhere in that the cursor doesn't change to a E_RESIZE_CURSOR when it's over a split panel divider. The code is in a large application too huge to post, and my attempts to simplify it have been unable to reproduce the problem. I have implemented the solution suggested in [http://forums.sun.com/thread.jspa?forumID=57&threadID=642994] but, although the mouse listener methods are indeed called, the cursor doesn't change. I have also tried calling setCursor on the parent of the JSplitPane, and on the JRootPane, but it doesn't change. In each case the mouse listener is called but the setCursor call has no effect.
    All the discussions on setCursor having no effect I've found are specific to JDialog. In my case, I have a deep window stack starting with JFrame, JRootPane, JLayeredPane, down through several JPanels, a JSplitPane, more JPanels, my JSplitPane, which contains 2 JPanels, and so on.
    What would prevent the JSplitPane divider from changing the cursor itself? Assuming it's trying, just as my explicit mouse listener is, what could be overriding, obscuring, or intercepting my cursor change?
    Any help would be most welcome
    Thanks!

  • Open an applet inside a JFrame?

    Hi all!
    I know this subject is kind of covered in previous topics, but my situation here is a little different.
    I have a TRENDnet TV-IP100 Internet Camera that uses a Java-Applet to show in a browser window the video it captures, using an xview.class file.
    I built a swing application that extends JFrame and I want to open in a JPanel, inside the JFrame, the applet-class that my camera uses.
    My problem is that I can't take and decompile that class file from the camera, in order to compile from the scratch the Applet; some could say illegal.
    So, I wonder if there is a way to open the class file inside my JFrame application. Also, I want to know if I can pass argumets in the JFrame file, like PARAM, NAME, VALUE, as there are important to start the applet.
    Thank you all, in advance.
    John_Astralidis.

    I have not tried this but if the Applet or JApplet class is to be used only as far as a component in a Container (JFrame.getContentPane() returns a Container) I see no problem with explicitly casting into a Panel or even a Container
    Panel p=(Panel)theAppletInstance;
    this.getContentPane().add(p);//this being the JFrame;There be problem of which I have not considered as the applet class is 'different' to many classes.
    Bamkin
    Message was edited by:
    bamkin-ov-lesta
    Container and Panel examples were used as Applet is derived from Panel, which is derived from Containter

  • JSplitPane divider (One touch expandable)

    Hi all,
    I am having some problems with the JSplitPane divider. I am using onetouch expandable.
    I want to stop the divider moving all the way up to the top of the window when the up arrow is clicked on. When you drag the divider up it stops near the top but doesn't go all the way up. but click on the up arrow on the divider bar and it rises completely to the top. How can I stop this from happening.
    I have managed to add an action listener to the buttons on the divider bar, In the action listener I do the following - splitPane.setDividerLocation(0.1);
    splitPane.updateUI();
    This works but then an exception is thrown -
    Exception occurred during event dispatching:
    java.lang.NullPointerException
         at javax.swing.plaf.basic.BasicSplitPaneDivider$OneTouchActionHandler.actionPerformed(BasicSplitPaneDivider.java:916)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
         at java.awt.Component.processMouseEvent(Component.java:3717)
         at java.awt.Component.processEvent(Component.java:3546)
         at java.awt.Container.processEvent(Container.java:1167)
         at java.awt.Component.dispatchEventImpl(Component.java:2595)
         at java.awt.Container.dispatchEventImpl(Container.java:1216)
         at java.awt.Component.dispatchEvent(Component.java:2499)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2458)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2223)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2132)
         at java.awt.Container.dispatchEventImpl(Container.java:1203)
         at java.awt.Window.dispatchEventImpl(Window.java:918)
         at java.awt.Component.dispatchEvent(Component.java:2499)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:134)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:101)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)
    Can anyone help me out?
    thanks,
    Paul.

    I have partial solution to the above problem but in doing so have encountered another problem that I can see no solution to. Can anyone help?
    I have a calss that extends BasicSplitPaneDivider and in this calss i overide the OneTouchActionHandler with a version that sets the top value to be the top of the frame + the height of the component I want left shown. My problem is that this code never runs. The origional OneTouchActionHandler in the BasicSplitPaneDivider runs not my version. How can I get my version to run.
    The version in BasicSplitPaneDivider is protected.
    This code never runs.
    <pre>
    * Listeners installed on the one touch expandable buttons.
    public class OneTouchActionHandlernew implements ActionListener {
         /** True indicates the resize should go the minimum (top or left)
         * vs false which indicates the resize should go to the maximum.
         private boolean toMinimum;
         OneTouchActionHandlernew(boolean toMinimum) {
         this.toMinimum = toMinimum;
    public void actionPerformed(ActionEvent e) {
    Insets insets = splitPane.getInsets();
         int lastLoc = splitPane.getLastDividerLocation();
    int currentLoc = splitPaneUI.getDividerLocation(splitPane);
         int newLoc;
         // We use the location from the UI directly, as the location the
         // JSplitPane itself maintains is not necessarly correct.
    System.out.println("The action listener is being used ");
         if (toMinimum) {
              if (orientation == JSplitPane.VERTICAL_SPLIT) {
              if (currentLoc >= (splitPane.getHeight() -
                        insets.bottom - getDividerSize()))
                   newLoc = lastLoc;
              else
                   newLoc = insets.top + 40;
              else {
              if (currentLoc >= (splitPane.getWidth() -
                        insets.right - getDividerSize()))
                   newLoc = lastLoc;
              else
                   newLoc = insets.left;
         else {
              if (orientation == JSplitPane.VERTICAL_SPLIT) {
              if (currentLoc == insets.top)
                   newLoc = lastLoc;
              else
                   newLoc = splitPane.getHeight() - getHeight() -
                   insets.top;
              else {
              if (currentLoc == insets.left)
                   newLoc = lastLoc;
              else
                   newLoc = splitPane.getWidth() - getWidth() -
                   insets.left;
         if (currentLoc != newLoc) {
              splitPane.setDividerLocation(newLoc);
              // We do this in case the dividers notion of the location
              // differs from the real location.
              splitPane.setLastDividerLocation(currentLoc);
    } // End of class BasicSplitPaneDivider.LeftActionListener
    </pre>

  • Problem while changing the JSplitpane in a dynamic way.

    Hi Everyone,
    In my application i'm changing the jsplitpane in a dynamic way.i'm posting the sample code thatz giving problem.Kindly compile and execute this.In the first frame i've done a split of two parts. The top component has got the name of the application and the bottom component has got some links related to that application. If the user click on this link ,i'm capturing the bottom component alone from the original splitpane and i'm breaking that into another split.
    upto this every thing works fine.Now the problem is when ever the user click on that link it'z capturing that event and doing consecutive split on the bottom frame.But i need that paricular split that user has already got to be repainted for all the time when user click on the link.Eventhough i've captured the main splitpane object in some other variable and assiging the same to the second window when user click on that url.But itz not recognizing that.
    Kindly some one help me to resolve this.
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GridBagLayout;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.Vector;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JSplitPane;
    public class Test2 extends JPanel // implements KeyListener
        static Vector<String> arrAppName = new Vector<String>();
        public static JSplitPane splitPane,splitPane2;
        public void AppWin(final JFrame frame)
            Container contentPane = this;
            GridBagLayout gb = new GridBagLayout();
            contentPane.setLayout(gb);
            arrAppName.add("link");
            JLabel lab = new JLabel("<html><font color=#6698FF><a href>" + arrAppName.get(0) + "</a></font></html>");
            contentPane.add(lab);
            JScrollPane listScrollPane = new JScrollPane(contentPane);
            JLabel label = new JLabel("APPLICATION REPORT", JLabel.CENTER);
            Font font = label.getFont();
            Font font3 = font.deriveFont(25.0f);
            label.setFont(font3);
            label.setFont(label.getFont().deriveFont(Font.ITALIC));
            label.setHorizontalAlignment(JLabel.CENTER);
            label.setForeground(new Color(0x736AFF));
            JScrollPane labelScrollPane = new JScrollPane(label);
            labelScrollPane.setVisible(true);
            // Create a split pane with the two scroll panes in it.
            splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
            splitPane.setTopComponent(labelScrollPane);
            splitPane.setBottomComponent(listScrollPane);
            splitPane.setDividerLocation(100);
            Dimension minimumSize = new Dimension(100, 50);
            listScrollPane.setMinimumSize(minimumSize);
            labelScrollPane.setMinimumSize(minimumSize);
              splitPane2= new JSplitPane();
              splitPane2=splitPane;
            lab.addMouseListener(new MouseListener()
                public void mouseClicked(MouseEvent arg0)
                    displayMainFrame("link", frame);
                public void mousePressed(MouseEvent arg0)
                public void mouseReleased(MouseEvent arg0)
                public void mouseEntered(MouseEvent arg0)
                public void mouseExited(MouseEvent arg0)
        public void buildWindow(String link, JFrame frame)
            Container contentPane = this;
            GridBagLayout gb = new GridBagLayout();
            contentPane.setLayout(gb);
            JLabel label = new JLabel("Next Screen", JLabel.CENTER);
            Font font = label.getFont();
            Font font3 = font.deriveFont(25.0f);
            label.setFont(font3);
            label.setFont(label.getFont().deriveFont(Font.ITALIC));
            label.setHorizontalAlignment(JLabel.CENTER);
            label.setForeground(new Color(0x736AFF));
            JScrollPane buildWindowtop = new JScrollPane(label);
            buildWindowtop.setVisible(true);
            contentPane.add(buildWindowtop);
           /*assigning the main split pane object for all the consecutive call*/
            splitPane=splitPane2;
            JSplitPane splitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
            splitPane1.setTopComponent(splitPane.getBottomComponent());
            splitPane1.setBottomComponent(contentPane);
            splitPane.setBottomComponent(splitPane1);
            splitPane.setOneTouchExpandable(true);
            splitPane.setDividerLocation(100);
            Dimension minimumSize = new Dimension(100, 50);
            buildWindowtop.setMinimumSize(minimumSize);
            splitPane1.setMinimumSize(minimumSize);
        } // end printing rows
        public static void displayFrame(String tname, JFrame framedisp, String buttonName, String tranCorrID,
            String buttonOption, JSplitPane buildSplit)
            Test2 mainDispPane = new Test2();
            framedisp.getContentPane().add(splitPane);
            framedisp.setVisible(true);
        public static void displayMainFrame(String link, JFrame framedisp)
            Test2 mainDispPane = new Test2();
            mainDispPane.buildWindow(link, framedisp);
            framedisp.getContentPane().add(splitPane);
            framedisp.setVisible(true);
        public static void main(String[] args)
            JFrame frame = new JFrame("MAIN WINDOW");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Test2 mainPane = new Test2();
            mainPane.AppWin(frame);
            frame.getContentPane().add(splitPane);
            frame.setSize(1280, 1000);
            frame.setVisible(true);
        } // end main
    } // end Test2Thanks in Advance,
    Siva.

    anybody can help me this regard?

  • JSplitPane divider does not change cursor in JDialog

    Hello,
    I am working with a JSplitPane added to a JDialog and when
    I try to move the divider the mouse cursor does not change
    to the resize cursor. If I add the JSplitPane to a JFrame it works
    ok. Is this a bug???
    Try the following code:
    JDialog d = new JDialog();
    d.add(new JSplitPane());
    d.setSize(640,480);
    d.setVisible(true);
    Thanks for any help!

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing
      JDialog d = new JDialog();
      public Testing()
        JSplitPane sp = new JSplitPane();
        d.add(sp);
        sp.setUI(new MyUI());
        d.setSize(640,480);
        d.setVisible(true);
      class MyUI extends javax.swing.plaf.metal.MetalSplitPaneUI
        public javax.swing.plaf.basic.BasicSplitPaneDivider createDefaultDivider()
          javax.swing.plaf.basic.BasicSplitPaneDivider divider = super.createDefaultDivider();
          divider.addMouseListener(new MouseAdapter(){
            public void mouseEntered(MouseEvent me){
              d.setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
            public void mouseExited(MouseEvent me){
              d.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
          return divider;
      public static void main(String[] args){new Testing();}
    }Message was edited by:
    Michael_Dunn
    [EDIT]
    will also need to add Cursor code for mouseDragged()

  • JSplitPane: how can I close one side of the jsplitpane?

    Hi!
    I have a jsplitpane component on my frame. I want to close one side of the jsplitpane when my program loads. And after some time I want to open it back..
    Do you happen to know how can I do that?

    Either you have not read the complete thread or you have not followed instructions correctly. Instead of adding HierarchyListener on JSpliPane, you are playing with divider before realization of split pane on screen.
    Here is modified code [This works 100%]:
    import java.awt.*;
    import java.awt.event.HierarchyEvent;
    import java.awt.event.HierarchyListener;
    import javax.swing.*;
    import javax.swing.plaf.basic.*;
    public class MySplit {
        private static void createAndShowGUI() {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                    new JButton("first"),
                    new JButton("second"));
            splitPane.setOneTouchExpandable(true);
            splitPane.setDividerLocation(150);
            splitPane.setPreferredSize(new Dimension(400, 400));
            splitPane.addHierarchyListener(new HierarchyListener() {
                public void hierarchyChanged(HierarchyEvent e) {
                    if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                        BasicSplitPaneUI ui = (BasicSplitPaneUI) splitPane.getUI();
                        BasicSplitPaneDivider divider = ui.getDivider();
                        JButton button = (JButton) divider.getComponent(1);
                        button.doClick();
            BasicSplitPaneUI ui = (BasicSplitPaneUI) splitPane.getUI();
            BasicSplitPaneDivider divider = ui.getDivider();
            JButton button = (JButton) divider.getComponent(1);
            button.doClick();*/
            frame.getContentPane().add(splitPane);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }Thanks,
    Mrityunjoy

  • 'dotted' / 'bumpy' background like JSplitPane divider

    Is there a way to get the background of a JPanel to have the nice 'dotted' (is 'bumpy' more correct ?) look of the light grey divider that Swing uses for such things as JSplitPane ?

    Too many panels you are having. Try none:
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    public class SplitExample {
         public static void main(String[] args) throws MalformedURLException {
              JLabel left = new JLabel("LEFT");
              URL url = new URL("http://weblogs.java.net/jag/bio/JagHeadshot-small.jpg");
              JLabel right = new JLabel(new ImageIcon(url));
              JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
              JFrame f = new JFrame("SplitExample");
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.getContentPane().add(sp);
              f.pack();
              f.setLocationRelativeTo(null);
              f.setVisible(true);
    }

  • Clicking on a JSplitPane divider.

    Hi,
    This may seem like a stupid question but, how can I detect clicks on the Divider of a JSplitPane? I can make it resize programmatically, and I simply want to resize it if it's double clicked on (according to the left component's preferred size).
    Many thanks.

    I do it this way:
    // frame class fields
    protected int splitPaneDefaultDividerLocation = -1;
    protected JSplitPane splitPane;
    // inside method for initialization of frame components,
    // after splitPane is created and added to the frame content pane
        SplitPaneUI spui = splitPane.getUI();
        if (spui instanceof BasicSplitPaneUI) {
          // Setting a mouse listener directly on split pane does not work, because no events are being received.
          ((BasicSplitPaneUI) spui).getDivider().addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              if (e.getClickCount() > 1) {
                if (splitPane.getDividerLocation() != splitPaneDefaultDividerLocation) {
                  splitPane.setDividerLocation(splitPaneDefaultDividerLocation);
                } else {
                  splitPane.setDividerLocation(0);
    // splitPane.getDividerLocation() returns last value passed to splitPane.setDividerLocation()
    // so at this point it returns -1 and cannot be used
        pack(); // Layout the components.
        splitPaneDefaultDividerLocation = splitPane.getUI().getDividerLocation(splitPane);

  • I would like to see the results divided in more pages

    Hi,
    I've done a search web application (whit JSP).
    After a search I would like to see the results divided in more pages with an index pages [ 1 2 3 4 5 6 ...] (like forum's page).
    How can I do?
    thank's,
    Marco

    My code is...
    <%
    articoli.find();
    if (articoli.oArticlesList!=null && articoli.oArticlesList.length!=0) {%>
    <hr noshade="noshade" align="center" size="1"></hr>
    Search Results...</br></br></br>
    <% for (int i=0; i<articoli.oArticlesList.length; i++) {%>
    <%=(i+1)%>)<a href="corpo.jsp?title=<%=articoli.oArticlesList[i.sTitolo%">"><b><%=articoli.oArticlesList.sTitolo%></b></a></br>
     Abstract: <em><%=articoli.oArticlesList[i].sOcchiello%></em></br>
    <%articoli.setRiferimento(articoli.oArticlesList[i].sTitolo);%>
    <%articoli.getReferenceNum();%>
    Referenced <%=articoli.oReferenceList.length%> times</br></br>
    <% }
    } else {%>
    No match found!
    <%}%>
    when the results are displayed I see them only in a page.
    I want to see them divided in more pages, like a search engine or this forum results ( pages [1,2,3,...] ) </a>

  • How to center the text in JLabel without image?

    I need to center the text inside JLabel, how do i do it?
    Also I need some advise, what is the best way to mark a clicked card (I'm making a card game)?

    I found this method that controls that text alignment:you can try few more:
    label.setVerticalAlignment(JLabel.CENTER);    //these two would  center the label contents
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setHorizontalTextPosition(JLabel.CENTER);Thanks!

  • Center the component without resize in JPanel

    Hi, I have a JPanel in a JFrame. I put in this JPanel objects that extends from a JPanel. It works all ok, but I want to center the components that I include. I use the BorderLayout.CENTER , but the components automaticly have resize it and this is verry bad.
    How can I make the center position of the components witchout to resize it?
    Thanks verry much!
    Nikolay

    BoxLayout is good. We use that almost exclusively for our GUI layouts.
    To centre both horizontally and vertically you can do this:panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS);
    panel.add(Box.createGlue());
    panel.add(component);
    panel.add(Box.createGlue());Regards,
    Tim

  • Viewing JavaDoc HTML files inside a JFrame

    hi all,
    how can I display any of JavaDoc HTML files (as overview-summary.html or index.html) inside a JFrame?
    in addition, the user should be able to use hyperlinks.
    I used JEditorPane, but in it I can't use hyperlinks.
    thanks for your answers. :)

    Hey thats something like a bew browser right if you want to i can send you an example for you but i'm curious you want to use JFileChooser or just open the html page like internet and provide links however send me a message to [email protected] to send you the example and watch if it works for you

  • ___Adding a ToolTip to the JSplitPane arrows___

    I have a JSplitPane that is set to OneTouchExpandable. I also disable the ability to have the user adjust the JSplitPane. Therefore, the user may only expand and contract the divider.
    Now I want to add a tool tip to just the two arrows (< and >) at the top of the divider on the JSplitPane. I am not sure how to do this.
    Any/All help is appreciated! Thanks!

    If anyone happens to come across this...I ran into problems implementing the solution. I would appreciate help at the following link: http://forum.java.sun.com/thread.jsp?forum=57&thread=384435&start=0&range=15#1680600
    Thanks!

Maybe you are looking for

  • How do i copy photos from a backup onto a new iMac?

    Long story short, I have had a lot of issues with and older iMac and iPhoto.  The geniuses were not able to get to root cause but I have a new iMac and I want to copy my photos from a backup into iPhoto.  In my backup I go into the backup and into Us

  • XI - BI connection

    Dear all, I'm developing some XI work which needs integration with a SAP BI system. However, there is no link set up between the systems. If I look in BI it cannot find/link to the SLD. Do you have any suggestions on how to accomplish the link betwee

  • Latest version of Oracle Application Server for AIX

    Hi, Can somebody help me with the latest version of Oracle Application Server available for AIX. The path where I can download the software and the steps to install. Thanks in advance. -Kiran.

  • Non Constructor Runtime error

    Here is the error: TypeError: Error #1007: Instantiation attempted on a non-constructor. at BitmapButtonExample()[C:\programming\flex\__FlexProfessional\Chap16\BitmapButtonExample.a s:33] Here is the code: package{ import flash.display.Bitmap; import

  • Made mistake and restored rather than synched, but got restore error.

    Help, my wife is going to kill me! I purchased two 3G's this morning and while attempting to sync one of the phones and move info from an old iPhone to the new, ran into a problem. My first operation went ok, (see my other post Transferring EVERYTHIN