How to get only the central panel to resize and display a scroll bar?

I have a window (frame) that has three panels - upper, middle and lower. When the window is narrowed down, I need a scroll bar is displayed for the central panel only. If the maximum possible vertical shrinkage would be the sum of the upper and lower panels and a small amount (to display the scroll bar of the central panel). So the upper and lower panels should always be completely (height wise). Please review my code and suggest corrections. I tried the couple in different ways, but without success... The code below is my latest attempt.
Thank you...
import java.awt.*;
import java.awt.Color.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.*;
import javax.swing.plaf.ComponentUI;

public class PanelResizingA extends JPanel implements MouseListener, MouseMotionListener
{

     /**
      * @param args
      */
     public static void main(String[] args)
     {
          JFrame frame = new JFrame ("All Panels");
          PanelResizingA allThreePanels = new PanelResizingA();
          JScrollPane allHorizontalScroll = new JScrollPane();
          //frame.add(allHorizontalScroll);
          allHorizontalScroll.setViewportView(allThreePanels);
          allHorizontalScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
          allHorizontalScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
          frame.getContentPane().add(allHorizontalScroll);
          frame.setVisible(true);
          frame.pack();
     }
     
     private JPanel topPanel;
     private JPanel midPanel;
     private JPanel bottomPanel;
     private JPanel allPanels;
     private JScrollPane midVerticalScroll;
     private JScrollPane allHorizontalScroll;
     private JLabel posnCheckLabel;
     private int panelWidth = 0;
     private int topPanelHt = 0;
     private int midPanelHt = 0;
     private int bottomPanelHt = 0;
     private int allPanelsHt = 0;
     private Point pointPressed;
     private Point pointReleased;
     
     public PanelResizingA()
     {
          createAllPanels();
     }
     
     private void createAllPanels()
     {
          topPanel = new JPanel();
          midPanel = new JPanel();
          bottomPanel = new JPanel();
          allPanels = new JPanel();
          posnCheckLabel = new JLabel("Label in Center");
          
          panelWidth = 300;
          topPanelHt = 150;
          midPanelHt = 200;
          bottomPanelHt = 150;
          allPanelsHt = topPanelHt + midPanelHt + bottomPanelHt;
          
          //topPanel.setMinimumSize(new Dimension(panelWidth-150, topPanelHt));
          //topPanel.setMaximumSize(new Dimension(panelWidth, topPanelHt));
          topPanel.setPreferredSize(new Dimension(panelWidth, topPanelHt));
          topPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
          
          midPanel.setMinimumSize(new Dimension(panelWidth-150, midPanelHt-150));
          midPanel.setMaximumSize(new Dimension(panelWidth, midPanelHt));
          midPanel.setPreferredSize(new Dimension(panelWidth, midPanelHt-3));
          midPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
          midPanel.setLayout(new BorderLayout());
          midPanel.add(posnCheckLabel, BorderLayout.CENTER);
          //midPanel.add(new PanelVerticalDragger(midPanel), BorderLayout.SOUTH);
          
          //bottomPanel.setMinimumSize(new Dimension(panelWidth-150, bottomPanelHt));
          //bottomPanel.setMaximumSize(new Dimension(panelWidth, bottomPanelHt));
          bottomPanel.setPreferredSize(new Dimension(panelWidth, bottomPanelHt));
          bottomPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
          
          allPanels.setMinimumSize(new Dimension (panelWidth-150, allPanelsHt-300));
          allPanels.setMaximumSize(new Dimension(panelWidth+25, allPanelsHt+25));
          allPanels.setPreferredSize(new Dimension(panelWidth, allPanelsHt));
          
          midVerticalScroll = new JScrollPane();
          //midPanel.add(midVerticalScroll);
          midVerticalScroll.setViewportView(midPanel);
          midVerticalScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
          midVerticalScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

          allPanels.setLayout(new BoxLayout(allPanels,BoxLayout.Y_AXIS));
          allPanels.add(topPanel);
          allPanels.add(midPanel);
          allPanels.add(bottomPanel);
          
          this.add(allPanels);
          addMouseListener(this);
          addMouseMotionListener(this);
     }
     private void updateCursor(boolean on)
     {
          if (on)
          {
               setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
          }
          else
          {
               setCursor(null);
          }
     }
     @Override
     public void mousePressed(MouseEvent e)
     {
          pointPressed = e.getLocationOnScreen();
          updateCursor(true);
     }

     @Override
     public void mouseDragged(MouseEvent e)
     {
          mouseReleased(e);
          pointPressed = e.getLocationOnScreen();
     }

     @Override
     public void mouseReleased(MouseEvent e)
     {
          pointReleased = e.getLocationOnScreen();
          
          Dimension allPanelsPrefSize = this.allPanels.getPreferredSize();
          Dimension midPanelPrefSize = this.midPanel.getPreferredSize();
          Dimension allPanelsSize = this.allPanels.getSize();
          Dimension allPanelsMinSize = this.allPanels.getMinimumSize();
          int midPanelPrefHt = midPanelPrefSize.height;
          int midPanelPrefWidth = midPanelPrefSize.width;
          int maxHtDelta = allPanelsPrefSize.height - allPanelsMinSize.height;
          //int deltaY = pointPressed.y - pointReleased.y;
          
          Point panelLocation = this.getLocation();
          Dimension size = this.getSize();
          if (size.height < allPanelsSize.height)
          {
               int deltaY = pointPressed.y - pointReleased.y;
               if (deltaY < maxHtDelta)
               {
                    midPanelPrefHt = midPanelPrefHt-deltaY;
               }
               else {midPanelPrefHt = this.midPanel.getMinimumSize().height;}
               this.midPanel.setPreferredSize(new Dimension(midPanelPrefWidth, midPanelPrefHt));
               this.midVerticalScroll.setViewportView(this.midPanel);
               allPanels.setLayout(new BoxLayout(allPanels,BoxLayout.Y_AXIS));
               allPanels.add(topPanel);
               allPanels.add(midVerticalScroll);
               allPanels.add(bottomPanel);               
          }
          midVerticalScroll.revalidate();
          pointPressed = null;
          pointReleased = null;
     }

     @Override
     public void mouseEntered(MouseEvent e)
     {
          updateCursor(true);
     }

     @Override
     public void mouseExited(MouseEvent e)
     {
     }

     @Override
     public void mouseClicked(MouseEvent e)
     {
     }

     @Override
     public void mouseMoved(MouseEvent e)
     {
     }
     
     
}
Published by: 799076 on October 8, 2010 12:53

Published by: 799076 on October 8, 2010 12:55

If you are using a BorderLayout, then Center will develop and reduce both the need and therefore should work as you wish. For example,.

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.*;

public class PanelResizingB extends JPanel {
   private static final Dimension PANEL_SIZE = new Dimension(300, 150);
   private String[] labelStrings = {"Top Panel", "Middle Panel", "Bottom Panel"};

   public PanelResizingB() {
      setLayout(new BorderLayout());

      JPanel[] panels = new JPanel[labelStrings.length];
      for (int i = 0; i < panels.length; i++) {
         panels[i] = new JPanel(new BorderLayout());
         panels.add(new JLabel(labelStrings[i]));panels[i].setPreferredSize(PANEL_SIZE);}

add(panels[0], BorderLayout.NORTH);add(new JScrollPane(panels[1]), BorderLayout.CENTER);add(panels[2], BorderLayout.SOUTH);}

private static void createAndShowUI() {JFrame frame = new JFrame("PanelResizingB");frame.getContentPane().add(new PanelResizingB());frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.pack();frame.setLocationRelativeTo(null);frame.setVisible(true);}

public static void main(String[] args) {java.awt.EventQueue.invokeLater(new Runnable() {public void run() {createAndShowUI();}});}} 

Tags: Java

Similar Questions

  • How to get only the whole ticks on a horizontal axis of a graph?

    Hello
    Could someone help me find oout how to get only the whole ticks on a horizontal axis of a graph?
    When I have a number less than 5, I get like 0, 0.2, 0.4 ticks... while I want it to be 0, 1, 2...

    Thank you
    Yann

    healer

    Try this Clara. Put this inbetween your chart labels:



    Set the interval to meet your needs of 'tick '.

  • How to get only the year of a date?

    I try to shoot only the year of a date and does not know how this can be done. I tried the SUBSTR function but its does not not how I think. What I want to do, it is write a condition indicating the year of birth of point = current year minus 23, I have a calc than the figures of the age of the difference in the date of birth and the current year, but I'd really like to just write a condition based just a years. Is this possible?

    Hello
    SUBSTR only works on a string. To extract parts of a date, you must use the TO_CHAR command.

    For the year, you would use this: TO_CHAR (the_date, 'YYYY')

    To_char takes 2 switches, the date to be handled and the part to be extracted, with the portion between apostrophes.

    Once you get used to manipulate dates as this other common areas are: DD - extracts the day of the month, MY snippet code to 3 characters for the month.

    For example, you can use this: TO_CHAR(sysdate,'DD-MON-YYYY') and it converts the current date, June 7, 2012 to June 7, 2012

    Hope this helps
    Best wishes
    Michael

  • How to get only the new lines

    Hello

    I have a table as below

    emp_id (integer)
    id_est (integer)
    dt_est (date)

    for each emp_id I have several id_est with several dt_est... as below

    emp_id id_est dt_est
    1 1 10-01 - 2009
    1 2 2009 - 01 - 13
    2 3 2009 - 01 - 10
    2 4 2009 - 01 - 12
    2 5 2009 - 01 - 14
    3 6 2009 - 01 - 12
    4 7 2009 - 01 - 15
    5 8 2009 - 01 - 17
    5 9 2009 - 01 - 19

    I would get just the news lines function date each emp_id, so my result should be as below

    emp_id id_est dt_est
    1 2 2009 - 01 - 13
    2 5 2009 - 01 - 14
    3 6 2009 - 01 - 12
    4 7 2009 - 01 - 15
    5 9 2009 - 01 - 19

    How I do that?

    Thank you

    Hello

    Try this code.

    Salim cordially.

    SELECT   id_emp, MAX (id_est), MAX (dt_est)
        FROM t
    GROUP BY id_emp
    
  • How to get back the default options without uninstalling and reinstalling firefox?

    I have the antiphishing settup according to the FAQ, but when I go to one of the test sites I don't am warned offshore but actually go on the test sites. I wonder if it is because a an entry in the allowed sites add ons installation has been removed manually recently and I don't know what has been deleted so that I can put it back. Maybe something of another also change to inappropriately. So, I would like to return to the default configuration set by Firefox.

    The mozilla.org site does not appear in the database of phishing protection, so for now to use the .com for a test site.

  • How to call only the operations of several connectors of ICF through simple connector server

    Hi Experts,

    I developed two connectors of the ICF (ICF1 and ICF2) and placed the beams of connector on the same server connector.

    Please guide me how to get only the authorities of each of the connector to call operations of each separately.

    I use following code-

    List of < ConnectorInfo > this.getConnectorInfoManager = cInfos () .getConnectorInfos ();

    System.out.println (cInfos.Size ());

    for {(ConnectorInfo cInfo:cInfos)

    APIConfiguration apiConfiguration = cInfo.createDefaultAPIConfiguration ();

    setPoolConfigurations (apiConfiguration);

    Discoveryendpointspecifie configProps = apiConfiguration.getConfigurationProperties ();

    this.setUpConfigurationProperties (configProps);

    ConnectorFacadeFactory facadeFactory = ConnectorFacadeFactory.getInstance ();

    ConnectorFacade connectorFacade = (apiConfiguration) facadeFactory.newInstance;

    connectorFacade.test ();

    }

    Methods of all connectors are called here to test and how do I selectively invoke test() selective connectors?

    Hello

    The connector of the ICF is called by these configurations in the 'Lookup.CONNECTOR_NAME. Research of configuration. The search name is configured in the COMPUTER resource

    We have the following values configured in the search based on who the connector class fires is

    Name of the connector

    org.identityconnectors.CONNECTOR_NAME. Connector

    Main connector class identity. It is the class that implements the SPI of the ICF framework operations.

    Name of the bundle

    org.identityconnectors.CONNECTOR_NAME

    Name of the identity connector bundle

    In Version

    11.1.1.5.x

    Version connector identity

  • How can I fix missing files that I can't get to the control panel?

    How can I fix missing files that I can't get to the control panel. I get error "Windows cannot find 'C:\WINDOWS\system32\rundll32.exe'. Make sure you typed the name correctly and then try again. To search for a file, click the Start button and then click on search"when I go to the control panel and click on add or remove the problem, and I get a similar message when I go to something similar

    Hello Braxtonspangler,

    I'm assuming that you get this error when you try to access some or all of the files/folders.  If this is the case, please see the link below.  Please let us know status.

    Microsoft Answers:

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_xp-files/Windows-cannot-find-cwindowssystem32rundll32exe/664c5b59-515C-472e-A872-a41f3e0562c1

    Thank you

  • I've lost the main screen for photoshop! I don't know what I did, but now when I open photoshop, I get only the tool bar at the top and a little on the sides. How can I go back to the normal screen?

    I've lost the main screen for photoshop! I don't know what I did, but now when I open photoshop, I get only the tool bar at the top and a little on the sides. How can I go back to the normal screen?

    Hi renaeb,

    Would you go to the Windows menu in Photoshop and check the option framework application from the drop-down list.

    Concerning

    Sarika

  • Uninstalled Potoshop Elements 7 on my old PC. Tried to install on the new PC, you get only "the code you entered is invalid." How can I install on my new PC, it's bought and paid for and if I look at my account, it is there. Could not find any e-mailadres

    Uninstalled Potoshop Elements 7 on my old PC. Tried to install on the new PC, you get only "the code you entered is invalid." How can I install on my new PC, it's bought and paid for and if I look at my account, it is there. Cannot find any e-mailadress support. What should I do?

    Error "serial number is not valid for this product". Creative Suite

    http://helpx.Adobe.com/Creative-Suite/KB/error-serial-number-valid-product.html

    Find the serial number of your Adobe product quickly

  • The only InDesign that appears on my CC is the trial version, how to get back the previous version? It is not even in applications to find "additional" and "view previous versions"!

    The only InDesign that appears on my CC is the trial version, how to get back the previous version? It is not even in applications to find "additional" and "view previous versions"!

    Follow these instructions carefully: How to find and install the previous Version of Adobe Apps in CC 2015 | Adobe Customer Care Team

  • Items purchased and it appears I have got only the part of editing photos and movies. How can I get part 2 of my order?

    Items purchased and it appears I have got only the part of editing photos and movies. How can I get part 2 of my order?

    Please post related queries from Photoshop Elements

    http://forums.Adobe.com/community/photoshop_elements

  • How to get all the icons on the desktop after installing xp

    After installation of xp only recycle bin makes its appearance. How to get all the other program on the desktop icons?

    Like internet explorer, my computer...

    Hello

    How to create a shortcut on the desktop?

    If the item is located in the start menu:

    1. click on start. The start menu appears.

    2 find the item that you want to create a shortcut. If the element is in a submenu of the menu, go to the submenu.

    3 right click on the element. A context menu is displayed.

    4. click on send to. A submenu appears.

    5. click on desktop (create shortcut). XP creates a shortcut to the item.

    _____________________________________________________________________________

    Here is the vista forums

    Try the xp forums at the below link for any other question of XP

    http://answers.Microsoft.com/en-us/Windows/default.aspx#tab=4

    Answers by topic

  • Suppose I have a table emp that has thousands of lines of data. In this table, I have to get only the employees whose salary is equal.

    Hello world

    Suppose I have a table emp that has thousands of lines of data. In this table of employees receive wages between 1000-10000.

    Now I have to get only the employees whose salary is equal.

    for example

    empNo empName sal

    -----------     -------------      ---------

    1 ram 5000

    2 5000 Shyam

    3 1000 Dilip

    4 deepak 2000

    5 sisi 1000

    6 1000 Priya

    so now...

    Now without using ' select * from emp where Sal IN (5000,1000). "How can I get these employees with the same salary?

    SELECT *.

    EMP e1

    WHERE EXISTS (SELECT 99 FROM emp e2 WHERE e2.sal = e1.sal AND e2.empno! = e1.empno)

    or maybe

    SELECT *.

    WCP

    WHERE sal IN (SELECT sal FROM emp GROUP BY sal HAVING COUNT (*) > 1)

  • \b in the transition from text to text elements. How to get just the plain text?

    I use C++ FDK and get TextItems with FTI_String from the active document. But the text in the text elements contains characters that do not appear in the text. For example, \b. What is this character and how can I get only the plain text without any character of metadata of FrameMaker.

    Ch,

    I think you could see tabs. Presented as an escape sequence, \b translates the BACKSPACE (0x08) ASCII character. For some reason, that's how the tabs are represented when you get the text of a document with the API. You expect to show that \t or ASCII 0 x 09, but they did not.

    There is no way to avoid retrieving a character entered by the user when you F_ApiGetText(). You must simply do a search and replace once you have the string in your code.

    I hope I understand what you're asking here.

    Russ

  • How to get around the problem of printing from the printer driver Adobe PDF for Notepad instead of a PDF Document?

    How to get around the problem of printing from the printer driver Adobe PDF for Notepad instead of a PDF Document? I tried the tool 'Repair Acrobat Installation' and other problems listed on the forums, but nothing worked. In the Notepad document is the following ' % [ProductName: distill] % X937B6DD4 not found, using the mail service.» X07BB154E not found, by using the messaging service. % [Page: 1] %% % [Page: 2] % % [Page: 3] % % [Page: 4] % % [Page: 5] % X4EEBB81F not found, by using the messaging service. %% [Error: invalidfont;] OffendingCommand: show; ErrorInfo: CharOffsets ss %% [Flushing: rest of work (end of file) will be ignored] %% %% [warning: PostScript error.] No PDF file produced. ] %%."

    The log file indicates that the Distiller cannot find fonts and besides, fonts with very weird names. (These names can often appear when printing from an application, WPF such as Internet Explorer 9, 10 or 11.)

    My best guess is that the problem is with the options set for the PostScript of PDF from Adobe printer driver instance. Exit the application you were initially impression since. Open the Adobe PDF printer Properties . Then click the Advanced tab. Then click on the button default printing . This should produce a significant window default print Adobe PDF is already opened in the Adobe PDF settings tab. On this tab, there is a checkbox to rely on system only fonts; do not use fonts in the document. If this box is checked, uncheck it and press apply , then OK. Then go to the general tab and press the button Preferences giving the window entitled Adobe PDF printing preferences. Again once, look for the box to rely on system only fonts; do not use document fonts. If this box is checked, uncheck it and press apply , then OK. Then back in the Adobe PDF Properties dialog box main, press apply (if it is enabled), and then click OK. Re-enter the app you were original print and try to print again. Let us know if that fixes the problem.

    -Dov

    PS: Unfortunately, rely on fonts system only turned on by default, causing problems for many applications. I always recommend turning it off (i.e., unchecking it)!

Maybe you are looking for

  • Is possible to install and play a game that requires an older version of the software?

    Is possible to install and play a game that requires an older version of the software? I get the message "cannot open the application because the classroom environment is no longer supported.

  • C55-b860 satellite is not booting

    Hi all I have a Satellite laptop c55, b860 which is not booting unfortunately. I disassembled it and deleted all the components that are connected to the MB, including hard drive, keyboard, and touchpad and also changed ram, but still the laptop does

  • U310 under Windows 8: a few questions

    G ' Day,. Lenovo U310, i5, improved W7 to W8 Two weeks ago, I upgraded my old U310 of three months of W7 to W8, and I met some problems unresolved since. See the Lenovo support seems like all vacationing maybe some of you forum-visitors can answer on

  • Add WAP300N to EA4500?

    I have an EA4500 which are currently operating here at home and you want to add a WAP300N (connected via electrician to one of the EA4500 Ethernet ports) to improve the coverage and 'assign' family members connect wirelessly to one or other of the de

  • Error code 800f080d while trying to install updates via windows update

    I received a large number of important security fixes for windows now, I see a lot of mistakes could help you fix this a.s.a.p. because I now have a non-secure system Original title: 2688338 error 800f080d