Sizing two panels in a frame

Hi,
i would like to set the size of two panels which are next to each other in a frame.
The left one should be about 5 times wider than the one on the right.
splitPane.setPreferredSize(new Dimension(1000,500));This one is not working.
Thx:
james

SplitPane is my right panel in the frame, this should
be 5x wider than the right panel, It should be 5x wider than itself?
So it is nothing to do with Splitpane, the problem is
that 1 add the splitpane and the buttonPanel to
mainPanel, and these 2 panels are which are added are
the same wide!You should have posted a Short,Self Contained, Compilable and Executable, Example Program.

Similar Messages

  • Hello everybody, Problem with Two panel in a Frame

    This is my first mail in this forum.I'm trying to learn java myself & have a problem in adding more than one panel in a JFrame.
    i should be able to add one panel which occupies 3/4 of a frame and another panel occupies the rest.
    Thanx in advance for anyone who helps me in sorting out this problem.

    You can use for example the GridLayout
    In your JFrame constructor, add lines below, it will add 2 colored panel in your frame
    Container container = getContentPane();
    container.setLayout(new GridLayout(1,2)); // 1 row, 2 cols
    JPanel panel1 = new JPanel();
    panel1.setBackground(Color.red);
    container.add(panel1);
    JPanel panel2 = new JPanel();
    panel2.setBackground(Color.green);
    container.add(panel2);

  • Adding a panel to a frame

    Hi! All,
    I'm new to java and i have a little problem here. I have created a frame and i want to put two panels inside it. well, i managed to put the first one, but i'm having problems with the second one. I want this second one to be added when I click on a button.
    The button that I will click is the new JButton i have defined. it is called draw. I really do not know what the problem is. I will apprecite any help. Below is my code.
    // My Code.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.util.*;
    public class Main extends JFrame {
    //all components I'll need
    public JButton draw;
    public JButton addFormula;
    public JButton modelCheck;
    /** Creates a new instance of Main */
    public Main () {
    super("Graphical Model Checker for Knowledge");
    //content pane is the main panel where i'll put everything
    JPanel contentPane = new JPanel();
    draw = new JButton("Draw");
    draw.addActionListener(
    new ActionListener() {         
    public void actionPerformed(ActionEvent event) {
    if(event.getActionComman().equals"Draw")) {               
    JPanel drawing = new JPanel();
    drawing.setBackground(Color.BLUE);
    drawing.setSize(100, 100);
    drawing.setLayout(new FlowLayout
    FlowLayout.CENTER));
    add("North", drawing);
    drawing.setVisible(true);
    contentPane.add(draw);
    addFormula = new JButton("Add Formula");
    contentPane.add(addFormula);
    modelCheck = new JButton("Model Check");
    contentPane.add(modelCheck);
    Canvas canvas = new Canvas();
    canvas.setSize(40, 40);
    canvas.setBackground(Color.white);
    contentPane.add(canvas);
    repaint();
    //add panel to the frame
    add("South", contentPane);
    //colours for window
    contentPane.setBackground(Color.yellow);
    //set layout manager
    contentPane.setLayout(new FlowLayout(FlowLayout.LEFT));
    addWindowListener(new CloseWindow());
    pack();
    setVisible(true);
    String [] fileItems = {"Open", "Save", "Rename"};
    String [] editItems = {"Copy", "Cut", "Paste"};
    //instantiate a menu bar object
    JMenuBar bar = new JMenuBar();
    JMenu file = new JMenu("File");
    for (int index=0; index != fileItems.length; index++)
    file.add(fileItems[index]);
    bar.add(file);
    setJMenuBar(bar);
    JMenu edit = new JMenu("Edit Graph");
    for (int index=0; index != editItems.length; index++)
    edit.add(editItems[index]);
    bar.add(edit);
    setJMenuBar(bar);
    public static void main(String args []) {
    JFrame window = new Main();
    }

    Don't forget to use the "Code Formatting Tags",
    see http://forum.java.sun.com/help.jspa?sec=formatting,
    so the posted code retains its original formatting.
    add("North", drawing); The "North" means nothing when adding a component to a panel using a FlowLayout. You should just be using:
    add( drawing );After you add the component to the container you need to use:
    frame.validate();

  • HELP - Syncronize two panels with scroll

    Hi, I need to syncronize two panels group in mode scroll.
    Ex: When the user moves the scroll in one panel, the other panel will have to move automatically. Any idea?

    thank you again.
    http://www.robotduck.com/content/articles/director/spriteBasics/scrolling/horizo
    this is not working.
    "duckets" <[email protected]> escribió
    en el mensaje
    news:ekpiil$8os$[email protected]..
    > Increasing your frame rate won't help because you're
    trying to do your
    > movement
    > within this repeat loop:
    >
    > repeat with D=1 to 70
    > sprite(1).loch=sprite(1).loch+1
    > end repeat
    >
    > That's not the right way to go about smooth scrolling,
    as you've
    > discovered.
    > It's doing a large jump because you don't see anything
    until the repeat
    > loop
    > has finished execting.
    >
    > Here's a demo movie which uses the behaviour example I
    provided above
    > (with a
    > small bug fix, I confused left and right in one place!):
    >
    >
    >
    http://www.robotduck.com/content/articles/director/spriteBasics/scrolling/horizo
    > ntal
    >
    >
    >
    http://www.robotduck.com/content/articles/director/spriteBasics/scrolling/horizo
    > ntalSteps
    >
    > hope this helps,
    >
    > - Ben
    >
    >
    >
    >
    >

  • Drag and Drop Between two Panels

    Hi,
    I am working with Swings,i created two Panels A and B. I kept some GIF or Image in Panel A,i would like to drag the gif object in to Panel B.
    when i try like this,my mouse could not communicate with two panels A and B.mouse events working Individualey,i mean mouse events working in same panel.
    Plz let me know how to communicate with two different panels with mouse. Drag and Drop between Panel A and Panel B.
    Thanking you
    MyProblems

    You might check out the Drag and Drop tutorial, especially the section Data Transfer with a Custom Component.
    Here's another approach using an overlayed non&#8211;opaque JPanel as a transfer device. The image label is transfered to the (fake) glass pane and dragged. On mouse release it is added to the JPanel below. Although I didn't build in any boundry&#8211;checking it would be a useful thing. Mostly to ensure a suitable drop target and component location in it.
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import javax.swing.event.*;
    public class DraggingTest
        public static void main(String[] args)
            LeftPanel left = new LeftPanel();
            JPanel right = new JPanel();
            right.setBackground(new Color(200,240,220));
            right.setLayout(null);
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            gbc.fill = gbc.BOTH;
            panel.add(left, gbc);
            panel.add(right, gbc);
            JPanel glassPanel = new JPanel();
            glassPanel.setOpaque(false);
            JPanel overlay = new JPanel();
            OverlayLayout layout = new OverlayLayout(overlay);
            overlay.setLayout(layout);
            overlay.add(glassPanel);
            overlay.add(panel);
            ImageMover mover = new ImageMover(left, right, glassPanel);
            glassPanel.addMouseListener(mover);
            glassPanel.addMouseMotionListener(mover);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(overlay);
            f.setSize(400,400);
            f.setLocation(600,325);
            f.setVisible(true);
    class LeftPanel extends JPanel
        Image image;
        JLabel label;
        public LeftPanel()
            loadImage();
            setBackground(Color.white);
            setLayout(null);
            label = new JLabel(new ImageIcon(image));
            label.setName("imageLabel");
            Dimension d = label.getPreferredSize();
            label.setBounds(40, 40, d.width, d.height);
            add(label);
        private void loadImage()
            String fileName = "images/dukeWaveRed.gif";
            try
                URL url = getClass().getResource(fileName);
                image = ImageIO.read(url);
            catch(MalformedURLException mue)
                System.out.println(mue.getMessage());
            catch(IOException ioe)
                System.out.println(ioe.getMessage());
    class ImageMover extends MouseInputAdapter
        LeftPanel left;
        JPanel right, glassPanel;
        JPanel activePanel;
        Component selectedComponent;  // imageLabel
        Point offset;
        boolean dragging, selected;
        public ImageMover(LeftPanel lp, JPanel p, JPanel gp)
            left = lp;
            right = p;
            glassPanel = gp;
            offset = new Point();
            dragging = false;
            selected = false;
        public void mousePressed(MouseEvent e)
            Point p = e.getPoint();
            // which panel is the mouse over
            if(!setActivePanel(p));
                return;
            // get reference to imageLabel or return
            selectedComponent = getImageLabel();
            if(selectedComponent == null)
                return;
            Rectangle labelR = selectedComponent.getBounds();
            Rectangle panelR = activePanel.getBounds();
            if(labelR.contains(p.x - panelR.x, p.y))
                activePanel.remove(selectedComponent);
                selected = true;
                glassPanel.add(selectedComponent);
                offset.x = p.x - labelR.x - panelR.x;
                offset.y = p.y - labelR.y - panelR.y;
                dragging = true;
        public void mouseReleased(MouseEvent e)
            Point p = e.getPoint();
            if(!contains(glassPanel, selectedComponent))
                return;
            glassPanel.remove(selectedComponent);
            setActivePanel(p);
            activePanel.add(selectedComponent);
            Rectangle r = activePanel.getBounds();
            int x = p.x - offset.x - r.x;
            int y = p.y - offset.y;
            Dimension d = selectedComponent.getSize();
            selectedComponent.setBounds(x, y, d.width, d.height);
            glassPanel.repaint();
            activePanel.repaint();
            dragging = false;
        public void mouseDragged(MouseEvent e)
            if(dragging)
                Point p = e.getPoint();
                int x = p.x - offset.x;
                int y = p.y - offset.y;
                Dimension d = selectedComponent.getSize();
                selectedComponent.setBounds(x, y, d.width, d.height);
                if(!selected)
                    activePanel.repaint();
                    selected = false;
                glassPanel.repaint();
        private boolean contains(JPanel p, Component comp)
            Component[] c = p.getComponents();
            for(int j = 0; j < c.length; j++)
                if(c[j] == comp)
                    return true;
            return false;
        private boolean setActivePanel(Point p)
            activePanel = null;
            Rectangle r = left.getBounds();
            if(r.contains(p))
                activePanel = left;
            r = right.getBounds();
            if(r.contains(p))
               activePanel = right;
            if(activePanel != null)
                return true;
            return false;
        private Component getImageLabel()
            Component[] c = activePanel.getComponents();
            for(int j = 0; j < c.length; j++)
                if(c[j].getName().equals("imageLabel"))
                    return c[j];
            return null;
    }

  • How to swap the controls contained between two panels?

    I want to swap all the controls contained between two panel? so can anyone please help?
    Thank you in advance

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Dim LIST1 As New List(Of Control)
    Dim LIST2 As New List(Of Control)
    For Each c As Control In Panel1.Controls
    LIST1.Add(c)
    Next
    For Each c As Control In Panel2.Controls
    LIST2.Add(c)
    Next
    Panel1.Controls.Clear()
    Panel2.Controls.Clear()
    Panel1.Controls.AddRange(LIST2.ToArray)
    Panel2.Controls.AddRange(LIST1.ToArray)
    End Sub

  • Resize panels in a frame

    Hi, I tried searching through the forums, but am obviously using the wrong search words.
    I have a JFrame with a JPanel in it. The JPanel is using the following layout:
    new BoxLayout (parentPanel, BoxLayout.LINE_AXIS)
    Then I added two JPanels to the parentPanel.
    But then I would like to click and drag the separator between the two panels to change the size of the two JPanels.
    Any hints?
    Thanks,
    Novice

    As it turns out I should have been looking at the JSplitPane class.
    Novice

  • Adding a JSeperator in between two panels

    Hi
    I want to add a JSeperator in between two panels.
    Just wondering to do this do I just say p.add(the seperator) or do I just have to insert the Seperator using section of the GridBagLayout manager Im using!?

    you can add to the content pane, in between the other panes, if they have been add to the cp, or if there is a main pane add to it, where ever the other panes are located....

  • Display 3 Panels in one frame.....

    Hi
    I need to display 3 different panels in one frame.
    The first panel will contain a JXTreeTable [North]
    The second Panel will contain a Tree [Center]
    The third Panel will contain a JXTreeTable [South]
    I am unable to get this working as the components to be displayed
    are not being placed properly.
    The JXTreeTable is being displayed only at the NORTH.
    Is it better to create 3 different panels or create just one panel with GridLayout(as I have done)
    Have I overlooked something in the code below?
    Thnx
    This is my code:
    public class PositionCostingView {
         public PositionCostingView(){
              initComponents();
         private void initComponents(){
              final JFrame frame = new JFrame("Position Costing");
              frame.setPreferredSize(new Dimension(450, 300));
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // First,testing my model
              TreeTableModel model = new OpTreeTableModel();
              JXTreeTable treeTable = new JXTreeTable(model);
              // Add the TreeTable to a Scroll Pane.
              JScrollPane scrollPane = new JScrollPane(treeTable);
              JPanel players = new JPanel(new GridLayout(3, 0));
              players.add(scrollPane);
              players.add(MyTree);
              players.add(scrollPane);
              JPanel content = new JPanel();
              content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
              content.add(players);
              frame.getContentPane().add(content);
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              new PositionCostingView();

    Please ignore my code on top.I am trying something else.....
    No offence meant please.

  • Make a square Panel inside a Frame (awt)

    Hi all. I have a Frame that contains an panel.
    The Frame has BorderLayout and panel is positioned Center in it, occuping all the space. However I want the Panel to be perfectly square.
    The Panel MUST have LayoutManager(null).
    If I call setSize(100,100) on Frame, the Frame incorporates the height to include the Windowsbar on top, and then the Panel won't be square.
    If I call SetSize(100,100) on Panel, the Frame don't display anything else than the Windowbar.
    How can I solve this? Am I missing something important?

    One more question please noah....
    My applet i dependent on the square panel like I said. However it is important that the applets Frame can be resized, but its panel must still be sqaure.
    My code goes as follows:
    class Spanel extends Frame{
        panel.setBackground(Color.red);
        panel.setLayout(null);
        panel.setSize(200,200);
        add("Center",panel);
        pack();
        show();
    this.addComponentListener(new java.awt.event.ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            int x = calculateFrameSize(e);
            panel.setSize(x,x);
            pack();
            show();
    calculateFrameSize() {
    // only returns the lowest number of
    //getWidth() and getHeight()
    }This code however will go in an infinite loop, calling
    COmponentResized over and over.
    How can I avoid the loop?

  • Changing panels on a frame depending on what the user clicks

    I'm making a small application with a JFrame and some JPanels.
    When the application starts a start panel is added to the frame where the user can press two buttons. If he presses a button, then a new panel must be painted on the frame. In the new panel there is a button for going back to the starting panel.
    How can I accomplish this changing of panels? How does one panel give control to another panel? How can I let the frame control everything (if I should do that)?

    I guess just use CardLayout, CardLayout will solve your problem

  • Help - Swapping of Two Panels triggered by JButtons in two separate Panels

    Problem: How to swap two Independent JPanels? Is it really possible?
    Some Information:
    Scenario 1:
    This implementation is easy if both panels was inside a Master Detail Panel (Add the first Panel and hide and remove if the Second Panel is triggered)
    //Sample Coding
    private JButtonTrigger_actionPerformed(ActionEvent e){
    FirstPanel.setVisible(false);
    FirstPanel.remove( );
    MasterDetailPanel(add.SecondPanel, null);
    SecondPanel.setVisible(true);
    Note: Assuming that the JButton was placed on Master Detail Panel
    Scenario 2:
    This is also easy if both are JFrames. In this sample code, This JFrame is calling another JFrame named Main( )
    //sample coding
    JFrame frame = new Main( );
    //Dimension screenSize declaration
    //getScreenSize( );
    //Getting the height and the width
    //Setting the location
    frame.setVisible(true);
    *** Now this is my problem, Is it really possible swapping two INDEPENDENT JPanels?
    Given
    1. There are two JPanels, (JPanelFirst, and JPanelSecond)
    2. JPanelFirst has JButton named "CallSecond", placed below of it.
    3. JPanelSecond has JButton name "CallFirst", placed below of it.
    4. "CallSecond" JButton must call JPanelSecond and "CallFirst" JButton must call JPanelFirst when the user presses the button.
    5. The principle is swapping.
    I have tried to implement this one but the swapping of JPanel does not work properly. I really need your help (sample code or sites recommended) and advice if it is really impossible to implement so that I have an alternative. Thanks for your time reading this.

    http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html

  • In the Animation Timeline panel menu "create frames from layers" is not showing.

    I am watching a tutorial on basic animation and when it gets to the point where they say to open the "Animation Timeline Panel Menu" the panel that opens for me is not the same one in the tutorial.  I am supposed to click on "create frames from layers" but that is not an option.  I'm confused as to why my panel is not the same as the one in the tutorial.

    It could be that you are using a different version of photoshop. Some of the older versions were split into two versions a standard version and an extended version, in most of those versions, it was required to have the extended version to use video editing features.
    Perhaps you could tell us what version of photoshop you have and what operating system.

  • Passing data from a panel to a frame / disposing of a frame from in a panel

    Hello, I have recently created a program where all windows are made of seperate frames, now, to make the whole thing a bit more appealing and professional looking, i'd like to make 1 main frame, and load my content panels into this 1 frame. Problem i'm having with this is passing data from the loaded in panel to the main frame, so the main frame can hide one panel to load another with data inserted in the first panel. OR another solution to my problem would be a way to dispose of a frame, but from within the seperate panel class. I have searched the www for a solution, but haven't found one so far, so, any suggestions or references to some info about this kind of issue? Any pointer is greatly appreciated

    kennethdm wrote:
    EDIT: I took a look at the cardlayout, and, although i see its relevance to my question, it still leaves me with the question how exactly i will pass data the user inputs into the first panel, to the second panel. The second panel is built by the info which is provided in the first panel.Stop thinking of them as Panels and start thinking of them as OOP objects that have data that must be shared. It's often a matter of using getters and setters and sometimes requiring a sprinkling of the Observer design pattern.

  • Need help putting together two scenes in one frame

    Hi Guys,
    I'm trying to put together a movie project. The thing is I wanted to put together two video captures in one frame - one on the left and the other on the right. I've been reading threads here in the forums and there have been varying answers (sometimes misunderstanding the question) so I would give examples.
    Here's an example: Do you know those movies where the guy and the girl sing a duet but they are in different locations and to give a cinematic effect, the movie will put their faces side by side singing the same lines?
    Another example is when the good and the bad guys are about to face each other from different directions, the scene would be split such that the left side shows the good guys and the right side shows the bad guys.
    Is there a way in iMovie to do this?
    Thanks guys!

    take a look at this: http://www.youtube.com/watch?v=B5rSr7Z7Vck&feature=channel

Maybe you are looking for

  • Sound click skip stutter mini 311

    I upgraded my Hp Mini 311 from Win 7 Home Premium to Win7 Pro. Since then every audio track I have skips EXACTLY 20 seconds from the end of a track (just like a dirty cd) regardless of the track length. I'm also unable to restore the mini to factory

  • Oo alv tree in background

    can we schedule a oo alvtree report in background. if cl_gui_alv_grid=>offline( ) is initial. CREATE OBJECT g_container_object "cl_gui_docking_container EXPORTING repid = gv_repid dynnr = '100' extension = '1500' EXCEPTIONS cntl_error = 1 cntl_system

  • How to install silverlight on OS X 10.10.2

    I've just bough a second-hand MacBook Pro, 13" 2.5 GHz Intel Core i5, and I've loaded up OS X 10.10.2. Whenever I try to download Silverlight I get the message "One moment, please, while the current Silverlight installation status is determined..." a

  • [NEW] gtkpacman

    I have created a PKGBUILD for a my friend who is writing gtkpacman, a frontend written in python, using pygtk, to pacman, the archlinux package manager. PKGBUILD # Contributor: Giovanni Scafora <[email protected]> pkgname=gtkpacman _svnrev=`LC_ALL=C

  • Conflict resolution for a table with LOB column ...

    Hi, I was hoping for some guidance or advice on how to handle conflict resolution for a table with a LOB column. Basically, I had intended to handle the conflict resolution using the MAXIMUM prebuilt update conflict handler. I also store the 'update'