Controlling the re-sizing of widgets:

I have read several Swing tutorials, but many are limited in their scope.
I have been searching for a way to control the resizing of my JPanels and widgets.
A solution I found is to use transparent JPanels that have no content or borders. I give them weights and directions that serve as counter-weights for the JPanels I want to display and control the sizing of. Here is my code:
public class Main extends JPanel {
    public Main() {
        super(new GridBagLayout());
        GridBagLayout gbLayout = (GridBagLayout) getLayout();
        setPreferredSize(new Dimension(250, 200));
        JPanel configPanel = new JPanel();
        configPanel.setBorder(new LineBorder(Color.blue, 2));
        configPanel.setPreferredSize(new Dimension(100, 50));
        GridBagConstraints configPanelGBConstraints = new GridBagConstraints();
        configPanelGBConstraints.fill = GridBagConstraints.HORIZONTAL;
        configPanelGBConstraints.anchor = GridBagConstraints.FIRST_LINE_START;
        configPanelGBConstraints.weightx = 0.4f;
        gbLayout.setConstraints(configPanel, configPanelGBConstraints);
        add(configPanel);
        JPanel padding = new JPanel(); // <--- empty JPanel that servers as a counter-weight to control the sizing of "configPanel"
        padding.setPreferredSize(new Dimension(150, 50));
        GridBagConstraints paddingGBConstraints = new GridBagConstraints();
        paddingGBConstraints.fill = GridBagConstraints.HORIZONTAL;
        paddingGBConstraints.anchor = GridBagConstraints.FIRST_LINE_END;
        paddingGBConstraints.weightx = 0.7f;
        gbLayout.setConstraints(padding, paddingGBConstraints);
        add(padding);
}So far, this is working ok.
Resizing objects in a JFrame is extremely important, and I'd like to ask if this is a "standard practices" way to handle re-sizing?
Maybe later on, I will get bitten by this bad technique?
What do good Swing programmers do?
Thanks.

camickr wrote:
A solution I found is to use transparent JPanelsYou could probably use Box.getHorizontalStrut(...) instead.
But I don't know exactly what you are trying to achieve and the code is not executable.
If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
sorry, I should of posted all my code that compiles:
import java.lang.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class Main extends JPanel {
    public Main() {
        super(new GridBagLayout());
        GridBagLayout gbLayout = (GridBagLayout) getLayout();
        setPreferredSize(new Dimension(250, 200));
        JPanel configPanel = new JPanel();
        configPanel.setBorder(new LineBorder(Color.blue, 2));
        configPanel.setPreferredSize(new Dimension(100, 50));
        GridBagConstraints configPanelGBConstraints = new GridBagConstraints();
        configPanelGBConstraints.fill = GridBagConstraints.HORIZONTAL;
        configPanelGBConstraints.anchor = GridBagConstraints.FIRST_LINE_START;
        configPanelGBConstraints.weightx = 0.4f;
        gbLayout.setConstraints(configPanel, configPanelGBConstraints);
        add(configPanel);
        JPanel counterweight = new JPanel();
        counterweight.setPreferredSize(new Dimension(150, 50));
        GridBagConstraints counterweightGBConstraints = new GridBagConstraints();
        counterweightGBConstraints.fill = GridBagConstraints.HORIZONTAL;
        counterweightGBConstraints.anchor = GridBagConstraints.FIRST_LINE_END;
        counterweightGBConstraints.weightx = 0.7f;
        gbLayout.setConstraints(counterweight, counterweightGBConstraints);
        add(counterweight);
    public static void createAndShowGUI() {
        JFrame mainFrame = new JFrame("test");
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JComponent newContentPane = new Main();
        newContentPane.setOpaque(true);
        mainFrame.setContentPane(newContentPane);
        mainFrame.pack();
        mainFrame.setVisible(true);
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
}This works.
So, I am just wondering if I should use the general construct that for every JComponent, it often makes sense to use an equal and opposing (sometimes transparent) JComponent to control its re-sizing?

Similar Messages

  • How do I control the size of a command buttoon in a table control?

    Hi,
    I was wondering if there is a way to control the height of a command button in a table control.
    There does not appear to be a column or cell attribute that can achieve this.
    Thanks!
    --Bill

    Hi Wolfgang,
    Thanks for the reply, I came to that conclusion as well. What I have is a mixed table with instructions that word wrap in one cell, a command button to log step completion, and I needed the row height to be set to the tallest cell contents, so all I really needed to do was set the word wrap for my text instruction cell, and then as each row is programmatically inserted and the table is populated call:
    SetTableRowAttribute(panel, table, row, ATTR_SIZE_MODE, VAL_USE_EXPLICIT_SIZE);
    SetRowHeightToTallestCellContents(panel, table, row);
    That will allow the row to be sized accordingly without having to worry about the number of visible text lines for the text cell.
    Thanks!
    --Bill

  • How do I install the Universal Crossword Print Widget?

    The Universal Crossword Print Widget has been discontinued, and there will be no new content. However, you can still receive the Universal Crossword printable by subscribing on your HP web-enabled printer’s front panel, or by visiting HPConnected.com (in the U.S.) or ePrintCenter.com (elsewhere). Note: You will need an HP web-enabled printer to subscribe.
    Here’s how to uninstall the Print Widget:
    Click the Windows Start button.
    Click Control Panel.
    Click Uninstall a Product.
    Select Universal Crossword Print Widget, then click Uninstall.
    Universal Crossword Print Widget (c) 2011 Universal Uclick. All Rights Reserved.
    I work on HP's behalf.

    Hi 57055:
    First of all, there is no charge of any kind for the Universal Crossword widget or any of the content. Any charges you are seeing are not for this application or for the crossword - if you are seeing charges and think they are for this application, something is wrong. You should look into having those charges cancelled if you do not know what they are for.
    Please run through the uninstall and reinstall steps one more time. The uninstall steps are very important - just deleting the icon, for instance, does NOT uninstall the program.
    So, first, uninstall. Follow the steps here: http://h30434.www3.hp.com/t5/ePrint-Print-Apps-Mobile-Printing-and-ePrintCenter/How-do-I-un-install-...
    Then reinstall, following the steps at the top of this thread (http://h30434.www3.hp.com/t5/ePrint-Print-Apps-Mobile-Printing-and-ePrintCenter/How-do-I-install-the...)
    I work on HP's behalf.

  • How to control the pixcel size in given tiff image

    Hai
    I loaded tiff image into the Frame by using the jai_core.jar and jai_codec.jar files. I am unable to control the pixcel size. It displaied default size. How to restract the pixcel on the image in Frame.
    import java.io.File;
    import java.io.IOException;
    import java.awt.Frame;
    import java.awt.image.RenderedImage;
    import javax.media.jai.widget.ScrollingImagePanel;
    import javax.media.jai.ImageLayout;
    import javax.media.jai.NullOpImage;
    import javax.media.jai.OpImage;
    import com.sun.media.jai.codec.SeekableStream;
    import com.sun.media.jai.codec.FileSeekableStream;
    import com.sun.media.jai.codec.TIFFDecodeParam;
    import com.sun.media.jai.codec.ImageDecoder;
    import com.sun.media.jai.codec.ImageCodec;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.imageio.ImageReadParam.*;
    class MultiPageRead extends JFrame
    ScrollingImagePanel panel;
    //     JFrame mainFrame = new JFrame();
         Container c;
         public MultiPageRead(String filename) throws IOException
    getContentPane();
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              pack();
              setTitle("Multi page TIFF Reader");
              setSize(980,1200);
              getContentPane();
    File file = new File(filename);
    SeekableStream s = new FileSeekableStream(file);
    TIFFDecodeParam param = null;
              ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);
    System.out.println("Number of images in this TIFF: " + dec.getNumPages());
              ImageLayout size = new ImageLayout(,0,12,12);
    // Which of the multiple images in the TIFF file do we want to load
    // 0 refers to the first, 1 to the second and so on.
    int imageToLoad = 0;
    RenderedImage op = new NullOpImage(dec.decodeAsRenderedImage(imageToLoad), null,
    OpImage.OP_IO_BOUND,
    size);
    // Display the original in a 800x800 scrolling window
    panel = new ScrollingImagePanel(op, 100, 200);
    getContentPane().add(panel);
         public static void main(String [] args)
    String filename = args[0];
    try {System.out.println("jfdfldjfldfjldjfjldjfjdjdjdjjdjdj");
              MultiPageRead window = new MultiPageRead(filename);
                        window.pack();
                        window.show();
              catch (java.io.IOException ioe)
              System.out.println(ioe);
    regards
    jaggayya

    Changing the fonts in Print using ABAP is not possible. as basic report output is a text editor.
    By changing "Customizing of Local Layout" will only change in display screen and not in print.
    One possible way to create a new printer formatr thry SPAD and use that format in while printing.
    to know more details about SPAD
    Using SPAD - SAP Spool Administration to print different paper size
    The SAP spool system manages its own output devices. This includes mostly printers, but also fax and archiving devices. In order for you to use output devices defined in your operating system from the SAP System, you must define these devices in the SAP spool system.
    Print to a dot matrix printer using computer paper with 66 lines
    Define paper types
    Formatting process Z_60_135
    Page format DINA4
    Orientation tick both Portrait and Orientation
    Type in the comment and click save
    Device initialization
    Device type - OKI341
    Formatting process Z_60_135 then click Execute
    Double click Printer initilization
    You must key the 66 lines hexadecimals for your printer. ( line no 9)
    1 # oki341 x_paper
    2 # reset
    3 # \e\0x40
    4 # select codepage multilingual 850
    5 \e\0x52\0x1a
    6 # disable skip perforation mode
    7 \e\0x4f
    8 # select 6 lpi
    9 \e\0x32
    10 # select page length 66 lines (66=hex $42)
    11 \e\0x43\0x42
    12 # select 10 cpi font
    13 \e\0x60
    CHECK THIS LINKS
    http://help.sap.com/saphelp_nw04s/helpdata/en/df/abbb3f8e236d3fe10000000a114084/content.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/5a/4df93bad37f87ae10000000a114084/content.htm
    http://www.geocities.com/SiliconValley/Grid/4858/sap/Basis/printprobs_solutions.htm
    Hope this helps you
    Regards
    Pavan

  • What is the Universal Crossword Print Widget?

    The Universal Crossword Print Widget has been discontinued, and there will be no new content. However, you can still receive the Universal Crossword printable by subscribing on your HP web-enabled printer’s front panel, or by visiting HPConnected.com (in the U.S.) or ePrintCenter.com (elsewhere). Note: You will need an HP web-enabled printer to subscribe.
    Here’s how to uninstall the Print Widget:
    Click the Windows Start button.
    Click Control Panel.
    Click Uninstall a Product.
    Select Universal Crossword Print Widget, then click Uninstall.
    Universal Crossword Print Widget (c) 2011 Universal Uclick. All Rights Reserved.
    I work on HP's behalf.

    Hi postofficemike,
    Sorry, but the program is only designed for Windows. The requirements for download are shown here:
    http://h30434.www3.hp.com/t5/ePrint-Print-Apps-Mobile-Printing-and-ePrintCenter/How-do-I-install-the...
    I have not heard any plans to make a version for Safari. You can get the same puzzle directly from U-Click though at this link:
    http://www.uclick.com/client/trn/fcx/
    Best of luck,
    Mary
    {I work on HP's behalf}

  • Is there a way I can control the resolution of the photos I transfer to the iPad?

    Is there a way I can control the resolution of the photos I transfer to the New iPad? I just received the new iPad and would like to reduce the size of the resolution of the pictures I am transferring.
    I have storage capacity issue and I am only able to transfer about half the number of pictures I had on original Ipad with the same storage capacity. I upgraded to the New Ipad and I am transferring all the pictures I had in the original Ipad. I do not know why they are not all transfering since the New Ipad got full before all the pictutres where transfered. I used Itunes to transfer the pictures I have in Iphoto .  I assume this is because the New Ipad has a higher resolution screen and is allowing the pictures to be transfered automatically to the New Ipad at a higher resolution than the original Ipad?
    Any thoughts?
    Ed

    edgodoy wrote:
    However, is there a way I can increase the number of pictures I can transfer to the New Ipad using Itunes?
    I have a Canon 7D and the picture are large.
    Step my step instructions, would be great if it is at all possible.
    What you as is difficult without knowing your exact circumstances, i.e. what format pictures are you sending, do you shoot in .jpg or shoot in RAW and convert to .jpg, etc.  However, I don't see a way to quickly reduce the size of your image files without reprocessing your files in some manner.
    You could export all of the images to be loaded onto your iPad in JPEG format using Lightroom or Aperture and greatly lower the quality setting in the .jpg export.  If you do this make sure you export to a new folder. Lowering the quality can have a huge impact on the size of the image files.  If this worked it would give you the advantage of still having the largest amount of pixels allowable on the iPad 3.  I found that on my iPad 2 I could 'get away' with setting the quality to around 50 without seeing any obvious changes.  A higher quality setting may or may not be required on the iPad 3, time will tell and as my iPad 3 is going back I've not taken the time to put more than a few sample (800 or so) images on it.  They were exported at a quality setting of 60 and look as well as can be expected considering my defective iPad 3 display.
    If you images are already exported at a lower quality setting and are still too large the next step would be to reduce the dimensions of the image.  Lightroom has this capability.  I don't know about Aperture, but I assume it does.
    My normal workflow with my 7D:
    Take picture in RAW.
    Transfer to Lightroom 4 converting the Canon RAW files to Adobe's DNG format.
    Process images in Lightroom.  If any need further processing then export to Photoshop and/or Nik plug-ins.
    Export processed images that I wish to have on my iPad to my Pictures folder in .jpg format using a quality setting of 60.  I do not reduce the dimension of the image as I want the maximum sized images my iPad will allow.  As I only transfer a couple of thousand size is not an issue.
    Use iTunes to Sync photos to iPad.
    As was mentioned by a previous poster you could use Photoshop to bulk process the photos but that requires both Photoshop and a knowledge of creating a bulk action.  Not hard, but very confusing if you haven't used both Photoshop and the bulk process before.
    There may be other methods that could work for you but I am not aware of them.  With the breadth of experience of the members of this forum perhaps someone else could chime in with suggestions.

  • Why did I get a "You Have Missed A Print" message with the Universal Crossword Print Widget?

    The Universal Crossword Print Widget has been discontinued, and there will be no new content. However, you can still receive the Universal Crossword printable by subscribing on your HP web-enabled printer’s front panel, or by visiting HPConnected.com (in the U.S.) or ePrintCenter.com (elsewhere). Note: You will need an HP web-enabled printer to subscribe.
    Here’s how to uninstall the Print Widget:
    Click the Windows Start button.
    Click Control Panel.
    Click Uninstall a Product.
    Select Universal Crossword Print Widget, then click Uninstall.
    Universal Crossword Print Widget (c) 2011 Universal Uclick. All Rights Reserved.
    I work on HP's behalf.
    This question was solved.
    View Solution.

    hi i'm a new user and i'd like to be able to print a PAST crossword from the Universal Crossword please know this is not a printing problem but i hope you will be able to help me find an archived crossword puzzle for April 24, 2012 Thank You!

  • How do I control the Facebook preview image?

    Help!
    How do I control the preview image that appears when link is shared on Facebook?
    Tried adding code snippet under the <head>, on html view of the page in Business Catalyst... with no luck.

    We have a pre-built Facebook Previews Widget over at MuseThemes.com that achieves this. Simply drag the widget out onto your page, and enter in your page description, title, category and link up an image. There's a complete training video included so you don't get stuck
    Check out the widget here
    Hope this helps! Cheers.
    Steve Harris
    MuseThemes.com

  • How do I un-install the Universal Crossword Print Widget?

    The Universal Crossword Print Widget has been discontinued, and there will be no new content. However, you can still receive the Universal Crossword printable by subscribing on your HP web-enabled printer’s front panel, or by visiting HPConnected.com (in the U.S.) or ePrintCenter.com (elsewhere). Note: You will need an HP printer to subscribe.
    Here’s how to uninstall the Print Widget:
    In Windows 7:
    Click the Windows button .
    Click Control Panel.
    If View By is set to Category, click Uninstall a Program under Programs (otherwise, click Programs and Features).
    Select the Universal Crossword widget.
    Click Uninstall. 
    Universal Crossword Print Widget (c) 2011 Universal Uclick. All Rights Reserved.
    I work on HP's behalf.

    Hi Mary56,
    If it is on your printer, it is not the widget, but a printer app. If it is on your computer, you have to uninstall the program (see directions at the top of this thread).
    I will send a note to Jaime, who helps with printer apps and he will get back to you if this is a printer app. If it is, it will help if you tell us the printer model number.
    Or, perhaps you can fix it yourself by checking out the instructions on this link:
    http://h30434.www3.hp.com/t5/ePrint-Print-Apps-Mobile-Printing-and-ePrintCenter/how-to-cancel-automa...
    Best of luck,
    Mary
    {I work on HP's behalf}

  • Controlling the Display of Animations using Advanced Actions

    Hi,
    I'm using Captivate 5.5 and having a bit of difficulty being able to control animations that are conditional on variables. I'm not sure what the best workflow is...
    I have set up five questions using the enhanced radio buttons widget and there is a 'tick' animation and a 'cross' animation next to each question which I want to play depending on whether the answer was correct or incorrect.
    In advanced actions I have set up five conditional actions so, for instance, IF 'question1variable = correctAnswer' then show the tick animation and hide the cross animation (Else... vice versa). These actions are linked to a 'check my answers' button.
    I have all the animations set to play for the duration of the slide, and this works fine except the playbar moves on (I need it to pause so that the students can keep reattempting the questions).
    How do I stop the playbar from moving on, so that the student can reattempt the questions as many times as they like, and each time the 'check my answers' button is pressed, the correct animation plays? I've tried things like rdcmndGotoFrame = rdinfoCurrentFrame - 1 (and variations of!) however, in this case the playbar will pause but the display of the animations becomes unpredictable and buggy
    Any solutions or ideas would be most appreciated
    Thanks in advance
    Rick

    Don't know if you can make this work but I did a similar thing using an action. I made the slide jump to slide=itself, eg if the question is on slide 17, I set it to jump to slide 17, in effect looping the slide -- but the user wasn't aware that was what was happening.There was a button to move on when done, but they could play all day. My questions were set to give rather complex feedback for both right and wrong answers. User could check each question and see the feedback on each choice. Don't know. Maybe.....  I used to do this using a javascript but now (5.5) you can select the current slide -- MUCH easier.

  • How to Control the Valves and Pump with Labview?

    I have started a new project where I have to control the valves operation through Labview 2009,using PXI 1031, NI 5105(Digitizer) and NI 6251(M-series DAQ).
    The valves I need to control using the labview are:
    a) Pressure Reducing Valve (open & close)
    b) Remote control Valve(On & Off) with in-built actuator
    c) Flow control valve(open, semi open, partially open, semi close, partially close, fully close), 1%, 2%, 3%..etc
    d)saftey valve (opening closing depending on increase in pressure from certian limit)
    I hav eto control
    a) Hydraulic pump operation with in built gear-box
    Please let me know, how should l develop the VI for all? How to get started?, any helpful links? If there is any example code?
    Its little urgent !

    If you are not familiar with LV, I would suggest you go through the tutorials. Then take the leap and figure out how to use Action Engines and State Machines (search any of the terms I used that don't understand, there are a zillion threads on them).
    Then...
    Sit down and write stand-alone testers for each of the widgets you are going to control monitor etc.
      These testers will give you an idea if they really work the way you think, their character, and will serve as a "Sanity Check" when you think you are going crazy  durring development.
    THen integrate the tester so they can all work at the same time. This will become a utility screen that will serve you well when maintaining the critter latter in its life.
    Only then...
    write out a complete set of state diagrams that describe what you plan to do (don't cheat! ) and walk through them in your head until you are cetain it will all work blah blah blah.
    This step is optional but highly recomened...
    Compose a detailed set of documemtns describing what you have in mind and post them here (include the images, they will get many mor readers) and let people  pick aprat your design.
    When you have a final design, use everything you learned along the way to be a kick-ass developer.
    Along the way post distinct well defined question on this site and as long as it looks like you are trying someone will probably reply and get you going again.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Hi Guys,  I am using the full width video widget on a site. The widget was working perfectly however I have just added additional content to the site and re-uploaded and now the video is not working! Please help I have tried everything and am freaking out

    Hi Guys,
    I am using the full width video widget on a site. The widget was working perfectly however I have just added additional content to the site and re-uploaded and now the video is not working! Please help I have tried everything and am freaking out as this web-site has been payed for by my client.
    Alex

    Many thanks.
    With those symptoms, I'd try the following document:
    Apple software on Windows: May see performance issues and blank iTunes Store
    (If there's a SpeedBit LSP showing up in Autoruns, it's usually best to just uninstall your SpeedBit Video Accelerator.)

  • How do I use the time capsule to share itunes music between multiple apple devices? Also, is it possible to control the music on one device using another, and how do you set this up?

    How do I use the time capsule to share itunes music between multiple apple devices? Also, is it possible to control the music on one device using another, and how do you set this up?

    unless i'm missing something, i think you got mixed up, this is easy google for walk throughs
    i'm assuming this is the new 3tb tc AC or 'tower' shape, if so, its wifi will run circles around your at&t device
    unplug the at&t box for a minute and plug it back in
    factory reset your tc - unplug it, hold down reset and keep holding while you plug it back in - only release reset when amber light flashes in 10-20s
    connect the tc to your at&t box via eth in the wan port, wait 1 minute, open airport utility look in 'other wifi devices' to setup the tc
    create a new wifi network (give it a different name than your at&t one) and put the tc in bridge mode (it may do this automatically for you, but you should double check) under the 'network' tab
    login to your at&t router and disable wifi on it
    add new clients to the new wifi network, and point your Macs to the time machine for backups

  • Remotely control the ITunes on Windows 7 64 bit PC with the new IPad

    With the latest version of ITunes for both Win7 and the new IPad, I'm only able to use the new IPad to remotely control the ITunes on Windows 7 64 bit PC through wired connection  ( ethernet cable ) to the wireless router. As soon as I connect my PC through wireless connection, the new IPad can not find my libraries.
    Is this a known issue or am I missing some settings?
    Thanks,

    Are you using the 64 bit installer?
    See also  Recovering your iTunes library from your iPod or iOS device.
    tt2

  • The sound of my iphone has dissapeared when I play games and when i listen to muisic but when I put the headphones the sound come back and I can control the sound,what should I do??

    I was on a boat ride when some water fell on it but it was just a little bit then when i tried to control the sound and volume while playing and listening to music it didn't showed anything and just with headphones it appeared again and i could listen and I could control it again but when i take the headphones out it goes back to the same thing.What should I do??

    try toggling the Ducking menuItem

Maybe you are looking for

  • Can't download Itunes to my new computer using windows 8.1

    I have tried to download Itunes and it pulls up the selection of a directory and then does nothing

  • Error when create DGMGRL configuration.

    When I add database standby in my configuration I receive this error message : DGMGRL> add database pij10g2 as connect identifier is pij10g2 maintained as physical;Error: ORA-16796: one or more properties could not be imported from the database Faile

  • Can't locate "Info" pane on iTunes to download Contacts

    I want to download my Outlook contacts onto my new iPod Touch. When i open iTunes, i can't find the "Info" pane. The last tab is "Photos" and i can't seem to stretch the screen any wider to find "Info". Can anyone help please? Thanks

  • Transferring characteristics to APO from ECC

    Hi, We need transferring characteristic to APO from ECC. Only one characteristic. We're enter name of characteristic to field "Additional characteristics", but in created IM chosen, all existing characteristics. What we need to do to transfer only on

  • Payment block without the approval

    Hi Gurus, my users need to be shown a message as" <b>this payment is blocked due the non-approval"</b> during the payment of unapproval of quality check of material. Pls help me out, its urgent. Satya.