Which LayoutManager for this topic

Hi there!
I'm trying to arrange 3 JPanels in a JFrame like this:
+------------------------+----------+
|  panel1                | panel2   |
+------------------------+----------+
|                                   |
|  panel3                           |
|                                   |
|                                   |
+-----------------------------------+On a resize, I want to maintain the relative size of the single panels, e.g.:
panel1.height = 1/4 of frame.height
panel3.height = 3/4 of frame.height
and the same for the widths of panel1 and panel2.
What layoutmanager would you recommend?

package gui1;
* LayoutDemo.java
import java.awt.*;
import javax.swing.*;
public class LayoutDemo extends JFrame {
    private JPanel jPanel1, jPanel2, jPanel3, jPanel4;
    public LayoutDemo() {
        super("Layout Demo");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setSize(400,300);
        setLocationRelativeTo(null);
        GridBagConstraints gridBagConstraints;
        jPanel1 = new JPanel();
        jPanel2 = new JPanel();
        jPanel3 = new JPanel();
        jPanel4 = new JPanel();
        jPanel1.setLayout(new GridBagLayout());
        jPanel2.setBackground(new Color(255, 255, 204));
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 2.0;
        gridBagConstraints.weighty = 1.0;
        jPanel1.add(jPanel2, gridBagConstraints);
        jPanel3.setBackground(new Color(204, 204, 255));
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.fill = GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanel1.add(jPanel3, gridBagConstraints);
        jPanel4.setBackground(new Color(255, 204, 204));
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.fill = GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 3.0;
        gridBagConstraints.weighty = 3.0;
        jPanel1.add(jPanel4, gridBagConstraints);
        getContentPane().add(jPanel1, BorderLayout.CENTER);
    public static void main(final String args[]) {new LayoutDemo().setVisible(true);}
}Message was edited by:
Andre_Uhres

Similar Messages

  • Potential improvements for this topic

    Hello -
       This topic has a lot of messages which would be beneficial to skip or hide.  1) Messages that have been moved to more appropriate topics, and 2) messages that are locked because they are referred to HP.  It would be very nice if a button existed to hide or omit these messages from the listing while browsing, thus zeroing in on the posts that are on topic.
       Thanks! - Randy

    Hey Randy,
    We manually remove placeholders for moved off-topic threads after a few days.  
    MrMatthew - HP Support Forums Moderator
    Click the Kudos star as a way to say "thank you" for helpful posts.
    Be sure to come back and click the 'Accept as Solution' button on the post that solved your issue - it may help someone else.

  • Which layout for this?

    Whis layout manager should I use for this type of gui? Any details about how to set it up would be aprreciated as well.
    http://www.kommi.com/images/fetch-panel.jpg

    which layout for this?You are not restricted to a single Layout Manager. Mix and match to get the desired effect.
    For example maybe start with a BorderLayout. Add one panel to the West and the other panel to the Center. The West panel might use a GridLayout. The Center panel might use a BorderLayout, then add the text area to the center and the progress bar to the south.
    Read the tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use Layout Managers and experiment for yourself.

  • Firefox can't load certain sites; your link for this topic doesn't work. Firefox 4, 5,6-Debian-6

    In the last week certain websites won't load. All I get is a blank page. Some of them: www.amazon.com, www.chron.com, www.microsemi.com.
    I was able to get on amazon.com by following a link for vendor feedback from an email but nothing else works.
    This problem exists with Firefox 4, 5, 6 and the default Debian browser Iceweasel. I am using Debian 6.0.
    Your link for this problem results in a page not found error.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    Try "Disable the hardware acceleration" in the Flash Player.
    *http://helpx.adobe.com/flash-player/kb/video-playback-issues.html
    See also:
    * https://support.mozilla.org/kb/Cannot+view+full+screen+Flash+videos
    Flash "Display settings" window:
    * http://www.macromedia.com/support/documentation/en/flashplayer/help/help01.html

  • Data aggregation: which solution for this case ?

    Hi all,
    I have a fact table where measures are referred to a single year. Outlining, something like this:
    year quantity
    1998 30
    1998 20
    2000 70
    2001 20
    2001 20
    I would to build a cube and then to analyze "tot.quantity for each year" but don't want aggregate "tot.quantity for all year".
    I haven't in my source database the "Year dimension" to mapping on year field.
    Do you have some suggestions on how to implement this and how to build cube using AWM tools (Year dimension and relative levels/hierarchies)?
    thanks.

    I am not sure I fully understand what you are trying to do, but from the example below you could create a single dimension called Year with one level of Year, add a hierarchy containing only one level, create a cube dimensioned by year and then map the table you have described below to the cube. As there is only one level in the dimension, no aggregation would performed by AWM.
    For the mapping you will need to create a view over your source table as follows:
    CREATE VIEW FACT_VIEW AS SELECT, YEAR, SUM(QUANTITY) FROM TABLE GROUP BY YEAR
    because AWM does not support an additive data loading model (surprisingly the API actually does but this is not exposed in AWM). You can only provide a single row for each dimension member. If you present multiple rows then the last row wins which in your example would result in the following data being loaded into AWM:
    1998 20
    2000 70
    2001 20
    If you create the view as shown above you should get the following data loaded:
    1998 50
    2000 70
    2001 40
    which is what I think you want?
    Hope this helps
    Keith Laker
    Oracle EMEA Consulting
    OLAP Blog: http://oracleOLAP.blogspot.com/
    OLAP Wiki: http://wiki.oracle.com/page/Oracle+OLAP+Option
    DM Blog: http://oracledmt.blogspot.com/
    OWB Blog : http://blogs.oracle.com/warehousebuilder/
    OWB Wiki : http://wiki.oracle.com/page/Oracle+Warehouse+Builder
    DW on OTN : http://www.oracle.com/technology/products/bi/db/11g/index.html

  • Which datastructure for this issue

    Hello there!
    Starting point as follows:
    I have a class Track. This Track consists of a bunch of Sectors.
    Each Sector consits of a start point (x1,y1) and an end point (x2,y2).
    For two successive Sectors s1 and s2 it follows, that:
    s1.x2 +1 == s2.x1We have something like that:
    s1.x1->s1.x2 -> s2.x1 -> s2.x2 -> s3.x1 -> ...
    Now I have two demands, which should be accomplished very efficiently:
    1) I want to access a specific Sector by its x-coordinate, i.e. something like that:
    track.getSector(xCoordinate) where xCoordinate lies between x1 and x2 of the wanted Sector.
    2) I want to sequentially traverse through the Track. In particular, I want
    start at a specific Sector. Sometimes at the first Sector, more often at some Sector in the middle.
    These demands are crying for a B* tree (or B+tree) with the x-coordinate as index and the leafs as the actual Sector-objects.
    Unfortunately, Java didn't serve any B*tree implementation. So I was wondering, if I could achieve my goals through a "supported" datastructure, maybe a TreeMap or something out of the Collection Framework.
    Unfortunately the second, I haven't much experience with TreeMap and his friends ;-)
    What would you recommend? Are you d'accord with my tendency toward B*trees or do you have another idea?
    Thanks!

    Well. I went to sleep too early, I guess :-)
    Thanks so far for the answers:
    @hunter9000:
    Is the second coord. of one sector always the same as the first coord of the next?Yes, it is.
    Which x will you use to retrieve a Sector, the first one or the second one?I need to use both. The problem is this: I have a x coordinate, i.e. a vertical line that cuts through my track and I need to have the Sector where that happens.
    @prometheuzz :
    Yes, that's what I want.
    @BigDaddyLoveHandles:
    Thanks, I will take a look at it. I didn't know the NavigableMap so far. I'll check it out.
    @marlin314
    You have a data structure, B-tree... No, I haven't. But I thought it would be ideal.
    ...you are not allowed to build a B-tree and must instead kludge something together our of say, a HashMap, which you don't understand.Well, I am allowed, but I would have to do the impl of the B-tree on my own or I would have to search one via google. As I wrote, I'm no expert of the Java Collection Framework and I wanted to know if it already brings some solution along.
    In any case, a B-tree is NOT what you want. Yeah, you're right. I didn't thought of the sector-x-coordinates beeing sorted. A B tree would bring no extra efficiency.
    (which you will have to write yourself) And how do I start with this the best? The algorithm is clear, I think. But I don't know where to start. Should I extend some existing List, e.g. ArrayList and only overwrite some methods or what? What is the most clever way to do that?

  • I think its close enough for this topic

    All you UK residents finaaaallly going to get your iPhone's tomorrow, what time are you planning to go?
    Im still not sure what to do, I have an O2 and CPW store 5 mins from me, and an Apple store 30 mins away. I ideally want to go to the Apple store (partly because there will be more of an 'event' there, partly because its in a mall and I dont have to queue in the cold!) but Im thinking it will be sooo much busier than the high street O2/CPW stores.
    I don't want to get to the Apple store to find a 200 strong queue and find out my friend went into my hometown and walked straight into an O2 store at 6.
    Hmmmm decisions.

    Just so this won't influence your decision: in the US you don't actually get your phone service set up when you buy. You do it online. I bought mine at the Apple Store, but on a recent trip to ATT, they were telling customers they had to do it online as well.
    The process only takes a few minutes and (in the US at least) includes porting over your current number. Not sure how it will be handled in GB.
    Another thing to factor in: I am assuming that the Apple Store will have 200 extra employees on duty for the event, while the O2 store will be understaffed as cell phone stores usually are.
    Enjoy your new phone.

  • Which pattern for this scenario ?

    Hi all,
    I have an EJB which connects to an external system (written in Perl) using plain HttpConnections and posting HTML content.
    I would like to centralize this access using a design pattern.
    Which pattern is would fit this scenario ?
    I wonder if I should use the Adapter pattern or the Bridge Pattern.
    What do you say to it ?
    Thanks
    Francesco

    I'd kind-of guessed it was uni work :-)
    in all honesty, I wouldn't even approach the problem from a patterns perspective. all I see is a subsystem I don't want to deal with directly, so I define an interface to hide it behind. could argue that it's an Adapter, since it's taking the Http interface and abstracting away from it, to a java one. on the other hand, since mucking around with Http in java isn't exactly straight-forward, you're defining a more simple interface, so it could be considered a facade. which do you think is closer?
    most people, once au fait with design patterns, think less in terms of those patterns, and more in terms of what OO principles to apply. score some extra credit by writing a passage about how design patterns are not prescriptive, and that many coders lift ideas about encapsulation and separation from patterns, rather than use the pattern exactly as described.

  • What licensing do I need for this use ?

    Lets say Im planning an application which does nothing but
    allows the user to upload Adobe PDF documents to our server. Then
    once on the server, parse the values from forms on the PDF's and
    extract the data. We wont be distributing Acrobat reader or any
    other Adobe product, but will provide a link where they can
    download the reader.
    Also, the PDF's would be created by someone with a copy of
    Acrobat pro. These PDF's will need digital signature capability.
    Can Acrobat reader handle signatures ?
    Here are my questions:
    - What licensing do I need, if any, in the above scenario,
    other than that for a copy of Acrobat ?
    - What are my options for capturing digitical signatures
    within a PDF and will the publicly available version of Acrobat
    reader allow the end user to sign the documents, provided they
    install the extra requirements for handling the signatures ?

    This isn't the correct forum for this topic, but I may be
    able to get you started...
    The licensing restrictions on gathering form data from PDFs
    is outlined in the EULA for Reader, I believe there is a limit of
    500 copies, but I could be wrong ... you should look at the EULA to
    be sure.
    Beyond that, try posting to the
    Acrobat
    Forums or contacting a sales rep at Adobe, they may be able to
    advise you further.

  • What i have to do for this exception and i am running my struts applicatio

    ValidatorResources not found in application scope under key "org.apache.commons.validator.VALIDATOR_RESOURCES"
    this is coding for ur reference
    <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
    <html>
    <head>
    <html:javascript formName="action2" dynamicJavascript="true" staticJavascript="true" />
    <%-- <SCRIPT>
    function set(target) {
    document.forms[0].dispatch.value=target;
    </SCRIPT>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    <html:hidden property="dispatch" value="error"/>
    <html:submit onclick="set('save');">SAVE</html:submit>
    <html:submit onclick="set('create');">SAVE AS NEW</html:submit>
    <Zhtml:submit onclick="set('delete);">DELETE</html:submit>
    --%>
    </head>
    <body>
    <h1>JSP Page</h1>
    <html:errors/>
    <html:form>
    config such as
    <form-beans>
    <form-bean name="dispform" type="org.apache.struts.validator.DynaValidatorActionForm">
    <form-property name="name" type="java.lang.String"/>
    <form-property name="password" type="java.lang.String"/>
    <form-property name="submit" type="java.lang.String"/>
    </form-bean>
    </form-beans>
    <action-mappings>
    <action input="/index.jsp" parameter="submit" name="dispform" path="/action1" scope="request" type="com.myapp.struts.dispatchaction">
    <forward name="save" path="/save.jsp"/>
    <forward name="delete" path="/delete.jsp"/>
    <forward name="modify" path="/modify.jsp"/>
    </action>
    <!-- <action path="/welcome" type="org.apache.struts.actions.ForwardAction" parameter="/welcomeStruts.jsp"/> -->
    </action-mappings>
    validation.xml file is
    <form name="action2">
    <field
    property="name"
    depends="required">
    <arg0 key="logonForm.username"/>
    </field>
    <field
    property="password"
    depends="required">
    <arg0 key="logonForm.password"/>
    <var>
    <var-name>mask</var-name>
    <var-value>^[0-9a-zA-Z]*$</var-value>
    </var>
    </field>
    </form>
    -----plz help me for this..................

    hey, I hope my experience will help for this topic: i use resin 2.1.17 and struts 1.2.9. the first problem i've found was in the the struts.jar, the class
    org.apache.struts.validator.ValidatorPlugIn
    didn't load the "pathnames" for the validator-rules.xml and validation.xml, to solve temporary the problem i addedin in the ValidationPlugin:
    protected void initResources()
    throws IOException, ServletException
    if(pathnames == null || pathnames.length() <= 0)
    // it was
    // return;
    // now is
    pathnames = "WEB-INF/validator-rules.xml,WEB-INF/validation.xml";
    etc...
    then the common-digester failed his job: the digester-rules.dtd file in the package org.apache.commons.digester.xmlrules has some dirty character not in UTF-8 encode. The method init () of the ValidatorPlugin class don't arise the SAXException that org.apache.commons.validator.ValidatorResources of common-validator.jar and org.apache.commons.digester.xmlrules.DigesterLoader classes throw because the dtd parsing fails.
    After this changes, my client side Struts validation wors, but i'm still working on it. I will write later more tips.
    ciao
    thomas

  • Which LayoutManager to use for this purpose.

    I am trying to set a panel inside JTableColumn. The panel consists of JTextField and a Button. The Button is very small in size and should appear in the SouthEast portion of the panel. The remaining space should be used up by JTextField. Which LayoutManager will help me achieve this. Here is a diagram of the layout of panel that I want.
    (----) stands for JTextField area and (||||) stands for the JButton.
    ------------------------|||||||||
    -------------------------------Please Note that the width of Panel is not known as it depends on the size of table column.
    regards,
    nirvan.

    Guys,
    Thanks for the replies. I achieve what I wanted using BorderLayout. Here is the program demonstrating what I was looking for. It's an SSCCE. The problem is solved.
    package com.ns;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.WindowConstants;
    public class PropertySheetLayout extends javax.swing.JFrame {
        // Variables declaration - do not modify
        private JPanel dummyPanel;
        private JTextField inputText;
        private JButton lookUpButton;
        private JPanel outerPanel;
        // End of variables declaration
        public PropertySheetLayout() {
            initComponents();
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            outerPanel = new JPanel();
            inputText = new JTextField();
            dummyPanel = new JPanel();
            lookUpButton = new JButton();
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            getContentPane().setLayout(new FlowLayout());
            outerPanel.setBorder(BorderFactory.createEtchedBorder());
            outerPanel.setPreferredSize(new Dimension(150, 75));
            outerPanel.setLayout(new BorderLayout());
            inputText.setBorder(null);
            inputText.setPreferredSize(new Dimension(100, 20));
            outerPanel.add(inputText, BorderLayout.CENTER);
            dummyPanel.setBackground(Color.white);
            dummyPanel.setPreferredSize(new Dimension(25, 75));
            dummyPanel.setLayout(new BorderLayout());
            lookUpButton.setText("jButton1");
            lookUpButton.setPreferredSize(new Dimension(25, 25));
            lookUpButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    lookUpButtonActionPerformed(evt);
            dummyPanel.add(lookUpButton, BorderLayout.SOUTH);
            outerPanel.add(dummyPanel, BorderLayout.EAST);
            getContentPane().add(outerPanel);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-408)/2, (screenSize.height-334)/2, 408, 334);
        }// </editor-fold>
        private void lookUpButtonActionPerformed(ActionEvent evt) {
            inputText.setText(JOptionPane.showInputDialog("Enter your Name"));
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new PropertySheetLayout().setVisible(true);
    }regards,
    nirvan.

  • When trying to update  Apps in iTunes on my computer my old Apple ID appears, which is no longer in use and has no password; even when I try to create a password for this Old ID, Apple won't let me. When I go into see my Account settings My new Apple ID /

    When trying to update  Apps in iTunes on my computer my old Apple ID appears, which is no longer in use and has no password; even when I try to create a password for this Old ID, Apple won't let me. When I go into see my Account settings My new Apple ID / iTunes ID are listed and the passwords are correct obviously so why can't I update my Apps?   Why does my Old apple ID keep appearing and how can I get Apple to change this?

    I have the same problem - it is maddening. I rely on this iPad for work so this is not just an annoyance! The above solutions of changing the appleid on the device or on the website do not work.
    The old email address no longer exists - I haven't used it in a year probably and I no longer have the account.  I logged into the appleid website and there is no trace of the old email address so there is nothing that can be deleted or changed there.  On the iPad there is no trace of the old email address so nothing can be deleted there either. I have updated the iPad software and the same problem comes right back.  Every 2 seconds I am asked to log in using the old non-existent email.  The device is currently useless.
    The only recent change to anything was the addition of an Apple TV device, which was set up using the correct login and password.
    Does anyone have any ideas? The iPad has been backed up to the iCloud so presumably it now won't recognize the current iCloud account? So restoring may notbe an option?

  • Is there a way to print from ipad 4 to a non AirPrint printer? I have a Canon Pixma MP 620 wifi which works fine with my PC but I don't want to buy a new printer. Is there an app for this or adaptors which could work?   thank, Ric

    Is there a way to print from ipad 4 to a non AirPrint printer?
    I have a Canon Pixma MP 620 wifi which works fine with my PC but I don't want to buy a new printer.
    Is there an app for this or adaptors which could work? 
    Thank, Ric

    Printopia is another option but be aware that since these solutions effectively act as a print server and AirPrint receiver, they require a computer to be running on the same WiFi network.
    Canon also has a couple of apps in the App Store that might facilitate this on non-AirPrint printers. Check out...
    Canon Easy-PhotoPrint
    Canon Mobile Printing
    PIXMA Printing Solutions

  • I bought a MBPro which came with Lion installed,i also wanted to have a copy of installation disc so i used mac app store.Normally if an app is already bought there is a warning or a sign that informs the buyer.I've charged for this download is it normal?

    Hi ,i bought a MacBookPro which came with Lion installed on it (i have registered my mac book pro right after i bought it), i also wanted to have a copy of the installation disc in case of a crash, so i used mac app store to get it.Normally if an app is already bought (for iphone app store) there is a warning or a sign that informs the buyer, than the app store lets the buyer to re-download/re-install the app.I've charged for this download afterwards, because i was using virtual credit card, there was not enough money transferred to that card during that download but the app store let me download it anyway. I haven't charged before the download, the app store first let me to download it then it requested that amount of money for next download wich it was a free app. Can anybody enlight me? thanks

    Hi ...
    i also wanted to have a copy of the installation disc in case of a crash
    If you have problems with your Mac you use Lion Recovery
    However, you can create your own installation disc >  How to create an OS X Lion installation disc | MacFixIt - CNET Reviews
    Since Lion came pre installed on your Mac, the App Store doesn't not recognize that as a purchase so you if you want to re download Lion to create a boot disk you will have to pay for it. You can then re download Lion on all your authorized Macs for free.

  • HT203052 How do I delete an icloud account which uses an email account no longer in use - I do not have the the passwrd for this account

    How do I delete an icloud account which uses an email account no longer in use - I do not have the the passwrd for this account

    You will need the password. If you can't get it reset via http://iforgot.apple.com (if you remember the answers to the account's security questions then you should be able to reset it via them) then try contacting Support in your country, they should be able to reset it.
    Contacting Apple about account security : http://support.apple.com/kb/HT569
    If your country isn't on that page then try this form and explain and see what they reply with : https://ssl.apple.com/emea/support/itunes/contact.html

Maybe you are looking for