How to dynamically resize JOptionPane

Hi All.
I have a JOptionPane that contains a JPanel as the message (BorderLayout). The JPanel has a JComboBox on the north part and another JPanel in the center. When the combo changes selection the panel in the center is changed. Basically the combo represents some sort of selection and the panel is changed based on the selection to enter some specific search criteria.
The problem I have is the search criteria panels are of different sizes. Therefore I want to resize the JOptionPane every time a combo selection is made.
Does anybody know how to do this?
nes

Hi ICE,
Here is some example code explaining my problem. Sorry it is a bit long but it explains my exact requirement.
< 74philip the problem with calling JOptionPane.createInternalFrame is that it does not block until the Ok button is pressed. That is why I cannot use this solution >
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class TestFrame3
    extends JFrame
    implements ActionListener
    protected JPanel m_panel = new JPanel( new BorderLayout() );
    protected JPanel m_propertyPanel1 = new JPanel();
    protected JPanel m_propertyPanel2 = new JPanel();
    protected JPanel m_propertyPanel3 = new JPanel();
    protected JDesktopPane m_desktopPane = new JDesktopPane();
    protected JComboBox m_combo;
    protected JButton m_button;
    protected JOptionPane m_pane;
    public TestFrame3()
        initGUI();
    public void actionPerformed( ActionEvent event )
        if ( event.getSource() == m_combo )
            switch ( m_combo.getSelectedIndex() )
                case ( 1 ):
                    m_panel.remove( m_propertyPanel1 );
                    m_panel.remove( m_propertyPanel3 );
                    m_panel.add( m_propertyPanel2, BorderLayout.CENTER );
                    break;
                case ( 2 ):
                    m_panel.remove( m_propertyPanel1 );
                    m_panel.remove( m_propertyPanel2 );
                    m_panel.add( m_propertyPanel3, BorderLayout.CENTER );
                    break;
                default:
                    m_panel.remove( m_propertyPanel2 );
                    m_panel.remove( m_propertyPanel3 );
                    m_panel.add( m_propertyPanel1, BorderLayout.CENTER );
                    break;
            //  THIS IS WHERE I WOULD LIKE TO RESIZE/PACK THE OPTION PANE
            //       m_pane.???????
            //  BUT HOW??
            m_panel.validate();
            m_panel.repaint();
        else if ( event.getSource() == m_button )
            m_pane = new JOptionPane();
            m_pane.showInternalConfirmDialog( m_desktopPane, m_panel,
                                              "Test",
                                              JOptionPane.OK_CANCEL_OPTION );
    private void initGUI()
        initSelectionCombo();
        initPropertyPanels();
        m_button = new JButton( "Go For It..." );
        m_button.addActionListener( this );
        getContentPane().setLayout( new BorderLayout() );
        getContentPane().add( m_desktopPane, BorderLayout.CENTER );
        getContentPane().add( m_button, BorderLayout.SOUTH );
        setSize( 800, 900 );
        show();
    private void initSelectionCombo()
        Vector v = new Vector();
        v.addElement( "Property Panel 1" );
        v.addElement( "Property Panel 2" );
        v.addElement( "Property Panel 3" );
        m_combo = new JComboBox( v );
        m_panel.add( m_combo, BorderLayout.NORTH );
        m_combo.addActionListener( this );
    private void initPropertyPanels()
        JLabel property1 = new JLabel( "Property 1" );
        JLabel property2 = new JLabel( "Property 2" );
        JLabel property3 = new JLabel( "Property 3" );
        m_propertyPanel1.setLayout( new GridBagLayout() );
        m_propertyPanel1.setBorder( BorderFactory.createLineBorder( Color.RED ) );
        m_propertyPanel1.add( property1,
                              new GridBagConstraints( 1, 2, 1, 1, 1, 1,
            GridBagConstraints.EAST, GridBagConstraints.REMAINDER,
            new Insets( 3, 3, 3, 3 ), 0, 0 ) );
        m_propertyPanel1.add( property2,
                              new GridBagConstraints( 2, 1, 1, 1, 1, 1,
            GridBagConstraints.EAST, GridBagConstraints.BOTH,
            new Insets( 3, 3, 3, 3 ), 0, 0 ) );
        m_propertyPanel1.add( property3,
                              new GridBagConstraints( 6, 5, 1, 1, 1, 1,
            GridBagConstraints.EAST, GridBagConstraints.BOTH,
            new Insets( 3, 3, 3, 3 ), 0, 0 ) );
        JLabel property4 = new JLabel( "Property 4" );
        property4.setBounds( 10, 10, 100, 20 );
        JButton property5 = new JButton( "Property 5" );
        property5.setBounds( 40, 60, 190, 40 );
        m_propertyPanel2.setBorder( BorderFactory.createLineBorder( Color.GREEN ) );
        m_propertyPanel2.setLayout( null );
        m_propertyPanel2.add( property4 );
        m_propertyPanel2.add( property5 );
        m_propertyPanel3.setLayout( new FlowLayout( FlowLayout.CENTER, 10, 10 ) );
        m_propertyPanel3.setBorder( BorderFactory.createLineBorder( Color.BLUE ) );
        JButton property6 = new JButton( "Property 6" );
        JButton property7 = new JButton( "Property 7" );
        JButton property8 = new JButton( "Property 8" );
        JButton property9 = new JButton( "Property 9" );
        m_propertyPanel3.add( property6 );
        m_propertyPanel3.add( property7 );
        m_propertyPanel3.add( property8 );
        m_propertyPanel3.add( property9 );
        m_panel.add( m_propertyPanel1, BorderLayout.CENTER );
    public static void main( String args[] )
        SwingUtilities.invokeLater( new Runnable()
            public void run()
                new TestFrame3();
}nes

Similar Messages

  • How to dynamically resize JPanel at runtime??

    Hello Sir:
    I met a problem, I need to resize a small JPanel called panel within a main Control JPanel (with null Layout) if I click the mouse then I can Drag and Resize this small JPanel Border to the size I need at runtime, I know I can use panel.setSize() or panel.setPreferredSize() methods at design time,
    But I have no idea how to do it even I search this famous fourm,
    How to dynamically resize JPanel at runtime??
    Can any guru throw some light or good example??
    Thanks

    Why are you using a null layout? Wouldn't having a layout manager help you in this situation?

  • How to dynamically resize taskflow popup set as inlineDocument.

    I've been trying to figure out how to dynamically set the WindowHeight and WindowWidth of a taskflow deployed as a inlineDocument popup. Sadly, neither the forums nor google came to the rescue so I had to actually figure this one out on my own. But at least now is my opportunity to work up some forum karma! :)
    Sample workspace containing the solution is here: http://www.williverstravels.com/JDev/Forums/Threads/2337969/MaxPopupSize.zip
    General Strategy for Solution:
    - Pull the browser height and width using Javascript
            function browserSize(evt)
              var button = evt.getSource();
              var agent = AdfAgent.AGENT;
              var windowWidth = agent.getWindowWidth();
              var windowHeight = agent.getWindowHeight();
              AdfCustomEvent.queue(button, "customEvent",
                width: windowWidth,
                height: windowHeight
              true);
              evt.cancel();
            }- Using a clientListener and serverListener, pull this information into a managed bean and set height / width in button's setWindowWidth(), setWindowHeight() attribute.
      public void onButtonClick(ClientEvent clientEvent)
        Double dw = (Double)clientEvent.getParameters().get("width")-100;
        Double dh = (Double)clientEvent.getParameters().get("height")-100;
        this.popupButton.setWindowWidth(dw.intValue());
        this.popupButton.setWindowHeight(dh.intValue());
        ActionEvent aE = new ActionEvent(this.getPopupButton());
        aE.queue();  
      }- Due to JSF Lifecycle complications, the managed bean will need to call a different button than the one which holds the client and server listener. It will be the second button (popupButton in the code above) which then calls the popup.
    Props to Frank for the client / server listener tutorial: http://www.oracle.com/technetwork/developer-tools/adf/learnmore/56-handle-doubleclick-in-table-170924.pdf
    Props to Martin Deh for the javascript insights: http://martindeh.blogspot.com/2011/03/dynamic-resizing-for-popup-dialogs.html
    Hope this helps someone down the road.
    Will

    Thanks LovettWB ...
    Your question helped me a lot...  I am able to pass these two parameters width/height to my bean and am able to set it to pop-up :)                                                                                                                                                                                                                                                                                                                                   

  • How to dynamically resize a Spark Label?

    If i set the text of a spark label at runtime, the label dont resize automatically. How can i resize the correct width of a spark label at runtime?
    Thanks in advance

    The sample will be helpful to you:
    <fx:Script>
            <![CDATA[
                protected function button1_clickHandler(event:MouseEvent):void
                    // TODO Auto-generated method stub
                    lbl.text = lbl.text + " hi ";
            ]]>
        </fx:Script>
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <s:Label id="lbl" height="20" text="hello" backgroundColor="#FFcc12" x="157" y="83"/>
        <s:Button label="ok" click="button1_clickHandler(event)"  x="177" y="152"/>

  • How to dynamically resize virtualbox console (Arch within Arch setup)

    My host is Arch, and my guest is Arch.  The guest running console without X.  I got 1024x728 resolution by adding vga=772 in guest's menu.1st file.  Is there a way to dynamically resize the guest's console dimensions by dragging virtualbox's window corner, as you can with a windows guest OS?

    Dynamic resizing only works from within X, it doesn't work when in console mode, as it requires the Guest Additions installed.  It might of course work in the future if Virtualbox includes a framebuffer driver with guest additions, but somehow I very much doubt they will

  • How to dynamically resize a display component to avoid vertical scroll bars?

    Hi,
    I have a Flex 2 chart embedded within my html page. I have a
    hard coded height and width for the object tag. The problem is that
    my Flex 2 chart application is created dynamically based on the
    meta-data and as such may or may not be bigger in size than the
    size that I have set. In such cases, Flex shows the scroll bar.
    On creationComplete, I want to be able to detect the true
    size of the flex app i.e size that includes both the view area and
    the area that is hidden but scrollable. I have tried height, width,
    verticalScrollBar.maxHeight etc. but none of them give me the
    height and width of the whole app. Is there a way to get that in
    ActionScript?
    Thank you,
    AN

    Hi!
    Try to read this:
    http://blogs.sun.com/winston/entry/button_header_table
    I hope it will help You.
    Thanks,
    Roman.

  • How do I stop iPhone Safari from dynamically resizing the visual viewport?

    Sorry I post this here, but I couldn't access the developer forums (no error given, it just keeps returning me to this page https://developer.apple.com/devforums/) I'm not even sure wether that's been moved here and it's just the redirection non working.
    I need to Stop iPhone Safari from dynamically resizing the visual viewport, or in other words, to stop it from trying to "fit" the layout into the viewport.
    Why?
    Because any recalculation javascript does on absolutely positioned elements makes the whole site super IRRESPONSIVE.
    I don't know wether the issue is the element going out the already-set layout viewport (which triggers the page resizing to fit the visual viewport) or just the calculations being made constantly, but I can stop the calculations from happening when not "touching" the screen, but I need a way to stop the page resizing.
    I tried setting the viewport width to 1040px, as my layout width, and it fixed the header's width being narrower than the body (or shifted left?), but the whole page is still resized with every motion-frame (one every 3 seconds, due to overloading the redrawing engine)
    Is there a way to prevent that?

    No, that link doesn't solve it. It just says the same is found everywhere online.
    There's probably no way to do it, as per their way they "accidentally" omitted the oposite case: the page being wider than 980. They only mention what to do if the site is narrower. Something I learned is big companies (with reputation management) could let you run in circles for years no answer rather than telling you something is not possible.
    I'm the developer (can't access the dev forums, don't know why) and I DID setup the viewport, scale and other properties but none of them stopped from re-fitting the new re-sized layout in the viewport. They just ensure the "initial" view.
    I think the feature I'm looking for must be achieved with some JavaScript function targeting Safari-proprietary variable/property… if even possible.
    I just had to make things never reaching the edge until somebody contributes something useful

  • Dynamically resize JTable cell to fit a JList

    Hi!
    I've been banging my head trying to add some dynamic behavior to a TableCellEditor. In short I'm trying trying to make it resize the height of the current row (the one it is in) to reflect the changes made to the JList used to let the user edit the cells value (which is a list of items).
    I've come across some threads dealing with the problem of resizing a cell to fit its content. This however is usually only done once (in the 'getTableCellEditorComponent' function) and so only provides half the answer. Also, since the editor is only active during cell editing I've been trying to make it revert to the old cell height after the editing is done.
    So far I have not come up with any decent solution to this problem and was hoping someone out there might have an idea or have read something similar and can point me to something helpful... anyone?
    Cheers!
    Teo

    The Swing tutorial on[url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html]How to Use Tables shows how to dynamically change the size to Table Columns.
    If you need help calculating the acutal size then try searching the forum. Using keywords "resize jtable column" (keywords I took directly from your topic title) I found some promising postings.

  • Dynamically resizing DefaultMutableTreeNode

    Does anyone know how to resize a DefaultMutableTreeNode after it's been created and initially sized? I have a tree that can be resized, but if I dynamically resize it so that some nodes are wider than the tree, I'd like the last few visible characters within the nodes to be replaced by three dots "..." instead of just clipping the text. The JTable does this when you resize a column.
    Thanks,
    Steve Sinai

    I change the two lines below:
    1. This: textField.text = val        to this:  textField.htmlText = val;
    2.  This: return textField.text;     to this:  return textField.htmlText;
    Here we go:
    import flash.events.Event;
    import flash.text.StyleSheet;
    import mx.controls.TextArea;
    public class DynamicTextArea extends TextArea
       public function DynamicTextArea(){
          super();
          super.horizontalScrollPolicy = "off";
          super.verticalScrollPolicy = "off";
          this.addEventListener(Event.CHANGE, adjustHeightHandler);
        private function adjustHeightHandler(event:Event):void{
          //trace("textField.getLineMetrics(0).height: " + textField.getLineMetrics(0).height);
          if(height <= textField.textHeight + textField.getLineMetrics(0).height){
            height = textField.textHeight;     
            validateNow();
        override public function set htmlText(val:String):void{
          textField.htmlText = val;
          validateNow();
          height = textField.textHeight;
          validateNow();
        override public function set height(value:Number):void{
          if(textField == null){
            if(height <= value){
              super.height = value;
          }else{       
            var currentHeight:uint = textField.textHeight + textField.getLineMetrics(0).height;
            if (currentHeight<= super.maxHeight){
              if(textField.textHeight != textField.getLineMetrics(0).height){
                super.height = currentHeight;
            }else{
                super.height = super.maxHeight;         
        override public function get htmlText():String{
            return textField.htmlText;
        override public function set maxHeight(value:Number):void{
          super.maxHeight = value;

  • Dynamically resizing VBoxes

    I have code that changes the cursor indicating user can drag
    to resize VBoxes vertically, horizontally, or diagonally, but I'm
    not sure how to proceed to dynamically resize the VBoxes.
    If the user has the vertical resizing cursor displayed (by
    clicking the top border of the lower VBox) and drags, the VBox
    above the border and below the border should both resize.
    Any ideas for how to proceed with this?
    Code is attached, and all you need are three images 16x16
    px.

    "Greg Lafrance" <[email protected]> wrote in
    message
    news:gnha8u$onj$[email protected]..
    >I have code that changes the cursor indicating user can
    drag to resize
    >VBoxes
    > vertically, horizontally, or diagonally, but I'm not
    sure how to proceed
    > to
    > dynamically resize the VBoxes.
    >
    > If the user has the vertical resizing cursor displayed
    (by clicking the
    > top
    > border of the lower VBox) and drags, the VBox above the
    border and below
    > the
    > border should both resize.
    >
    > Any ideas for how to proceed with this?
    Use VDividedBox instead?

  • Dynamically Resize Flex Layout

    I am using flex inside a coldfusion page and would like to
    know how to dynamically make my swf height to fit my application.
    I have a search application and the details text get cut off.
    now I could make it scroll but would like to be able to make the
    swf height expand so my browser page can scroll. Is this possible?
    I Thought of Application.application.height but nothing. I do
    know the code is in the height in the page that resizes it, but if
    I set this to 100% can't I set the variable inside my application?
    Please help!

    LinkMc,
    If you are using the standard template it has css that says:
    body { margin: 0px;
    overflow:hidden } <- Take out the overflow:hidden. That
    is the first step. There is also a "<body scroll="no">". I
    took out the scroll='no' just to be sure. I ended up wrapping the
    javascript in the page in a <div>. Then I set the height to
    the size of the app. When the app shrinks and grow I adjust the
    height so the footer doesn't just sit at the end of a lot of
    scrolling.
    as3 --> flash.external.ExternalInterface.call(
    "adjustDivHeight", "950" );
    <script language="JavaScript">
    function adjustDivHeight(height) {
    e = document.getElementById( 'bigMo' );
    e.style.height = height + 'px';
    </script>
    Also, a couple issues I saw with IE. Does the list ever end.
    // if we've detected an acceptable version
    // embed the Flash Content SWF when all tests are passed
    AC_FL_RunContent(
    "src", "acuminderFX",
    "width", "762",
    "height", "100%",
    "align", "middle",
    "id", "acuminderFX",
    "quality", "high",
    "bgcolor", "#ffffff",
    "name", "acuminderFX",
    "flashvars",'base=https://www.jnjvision.com/',
    "allowScriptAccess","sameDomain",
    "type", "application/x-shockwave-flash",
    "pluginspage", "https://www.adobe.com/go/getflashplayer",
    "wmode", "transparent" <-- Get rid of IE black box
    // In IE the swf comes up as a black square until you roll over
    it with the mouse.
    // This focuses on the swf so that IE will pass it control.
    var acuFxObj = document.getElementById( 'acuminderFX' );
    if ( acuFxObj != null ) {
    acuFxObj.focus();
    If you look at https://www.acuminder.com/ you can see what I
    did to make it work. Also because it is secure I had to make some
    changes to the history.js. IE won't load it secure if you don't fix
    the history.js
    That should be a good start.

  • How do you resize multiple artboards in Illustrator at the same time?

    Hi,
    This is a question that has been bugging me for a while.  I'm currently on CS6 but I'm looking for a solution that can also work on CS5 for a co-worker.
    Having multiple artboards has been established since CS4 and I have yet to see an official way of resizing multiple artboards, if anything there should at least be a plug-in.
    As great of a feature it is, it seems a little short sited.  If one has multiple artboards one should be able to manage multiple artboards, right?
    I totally love having multiple artboards but I should be able to resize and manage multiple artboards as well.
    This is great for building icon sets but how can I resize the set all at once?
    I was considering trying to do an action but odds are I still would have to select an artboard one by one to do which doesn't save much time if you have like 30 artboards to apply this to. 
    I don't even see a batch render for artboards and Photoshop has that for its files.
    I'm well aware of the solution that is displayed here:
    http://forums.adobe.com/thread/1093465
    Which is a script.  I'm not sure where I'm supposed to put it.

    mec_os wrote:
    you can resize the artwork on export. no need to draw it to size.
    Unfotunately when I looked into that does not seem to be the case.  However I can resize when I "Save for Web" but that appears to only work for one artboard at a time.  I can Save As or Export multipe artboards but not adjust the size.  Believe me I would be happy if I could resize multiple artboards upon export but apparently that is not an option.
    mec_os wrote:
    you can put the scripts in illustrator's folder/presets/en_us(or whatever localization you have)/scripts. you can then access them in illustrator from the menubar/File/Scripts/
    there are also applications that will let you execute scripts with assigned shortcuts. i believe sparks is free.
    Thanks for pointing out the location. 
    Do I save it as a txt file or something else?
    (I was guessing that I would copy the script into notepad or something)

  • I am using a doc formatted on excel --- how do i resize the doc to fit on one page?

    I am using a document that was formatted in excel (on a PC) --- how do i resize the document to print on one page?

    Hi phylw,
    Here is one way. View > Show Print View. At the bottom of the window is a slider control called Content Scale. Slide to the left to shrink the document.
    Under File > Print... you will see a print preview that tells you how many pages the document now occupies.
    Regards,
    Ian.

  • How can I resize a photo in iPhoto without cropping it?

    I am taking pictures on my iphone 4s and using iphoto to edit them on macbook pro.  I need to upload these photos at a size much smaller than what i am able to take with my phone.  The only way I see to adjust the size of a photo in iphoto is to crop it.  How can I resize without cropping?
    Thank you

    It's an option in the Export menu.
    File -> Export and under the Size option you can choose the maximum you prefer. Export that and upload from the desktop.

  • How to dynamically determine Receivers within BPM

    I’m trying to design a way to determine my receivers within my BPM process during runtime.   My Scenario is as follows:
    SAP IDOC
        V
      XI
                 XI uses JAVA Mapping MT1 to determine vendors and if customer receives PIDX
                             JAVA Mapping MT2 to creates the PIDX output file if required
      V
    SENDs to required Vendor (PIDX if required otherwise email)
    My problem is how to dynamically determine the appropriate receiving vendor for my PIDX.
    I can not use the condition editor on the standard Receiver Determination because the output message (PIDX) doesn't have specific enough information to determine the vendor.
    Other than the customer number there are no other values and we don't want to use customer number because each vendor can have multiple customer numbers (hundreds).
    I've tried various attempts but none seem to work.  This could also be because I have limited knowledge of BPMs and this is my first complex development.  Below are the different attempts I've made at dynamically determining the receiver.  Any input would be appreciated.
    Receiver Scenario 1 
      I developed an interface mapping with MT1 as input and the SAP Receiver Determination as output.  The problem is for me to use this, the interface mapping had to reference the PIDX output (MT2 instead of MT1) which has no data that I can use to determine the receiver.
    Receiver Scenario 2
    I added a receiver step right before my send step and used the receiver list.  This appears to send the PIDX to everyone in the list and there is no way to evaluate or eliminate a name from the list. 
    Receiver Scenario 3
    I created a context object in the Integration Builder and assigned it to a field in MT1.  I then added a switch step with a branch for each vendor.  Within each specific branch there is a Send step that has the context object name I created in the "Send Context" field.  However, on the configuration side I’m unable to access the context object which I created on the design side.  Whenever I open the condition editor and select the radiobutton for "Context Object" the list  does not include the context object I created in the Integration Builder.

    Hi,
    Try using the enhaced receiver determination concept.
    Maybe based on certain field values you can write a UDF which calculates the receiver.
    Try this Blog out
    Link : [
    http://help.sap.com/saphelp_nw70/helpdata/en/43/a5f2066340332de10000000a11466f/frameset.htm]
    Regards,
    Abhishek
    Award if helpful.

Maybe you are looking for

  • How can I turn off my built-in camera?

    It stays on even after I restart my computer, although I'm not using any software that uses the camera. Plus, this is creepy. I've got a 2-yr-old mac air running os 10.8.5

  • How to check whether transport path exist between two systems in sld??

    Hi,      I have two systems namely 'A' and 'B' and created business systems for both of them.Then i created transport path between the two systems.How i check whether what i have done is right in SLD.

  • Java Mapping for JDBC Interface

    Hi, please help on java mapping for my jdbc interface. my java code for jdbc is: Created on May 7, 2008 TODO To change the template for this generated file go to Window - Preferences - Java - Code Style - Code Templates package XiMappingDB2.com.xi.te

  • HTTP Strict Transport Security support in Weblogic 10.3.3+

    Hi Gurus, 1) Does Weblogic 10.3.3+ support HTTP Strict Transport Security (HSTS)? 2) Has anyone experienced with implementation of the HTTP Strict Transport Security (HSTS) header in Weblogic 10.3.3? Thanks in advance. James

  • Posting Intercompany Vendor invoice

    Hi All, While posting the intercompany vendor invoice via VF01 the Idoc generated by RD04 output is errored out with the below error: Field BSEG-MWSKZ . does not exist in the screen SAPMF05A 0302 Please advice...... Rgds Prasad