JFrame resize dynamically in response to content pane size changes

Hi -
I have a JFrame that uses CardLayout. The CardLayout panel content is of varied dimensions. it means the JComponents added to CardPanel will change size dynamically.
Is it possible to have the JFrame resize dynamically in response to the content of the CardLayout panel changing?

camickr wrote:
No, the preferred size of a panel using a CardLayout is the preferred size of the largest component added to it.
As a user I think it would be terrible to have the frame resize every time a turn a page to go to the next card. I have never seen this any any application.
If you really need this functionality, then manage the panels yourself. Remove the existing Component before adding the next component and then do a frame.pack().My Application will be a JFrame.
inside this JFrame i want to have three JPanels. according to some events and logic my GUI should switch to a given JPanel from those three panels. as i said the Jpanels sizes will change size on runtime depending on a automatic swing JPanel generation and i will have to add the new generated JPanel to parent JFrame with its new size
any Ideas how to achive this ?

Similar Messages

  • Content pane size

    Ok I really feel stupid asking posting this ;)
    I am writing a new application and its is a JTabbedPane.
    When I execute the code the contentPane is really small (like 90x1).
    I have to grab the corner to make it large enough that I
    can see the tabbed pane.
    How can I force the contentPane to be specified size ?
    Here is the code :
    import java.lang.*;
    import java.awt.datatransfer.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import java.lang.Float.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import javax.swing.table.AbstractTableModel;
    public class scanTool extends JFrame implements ActionListener {
    public scanTool(String argv[]) throws IOException {
    super("Vanguard Scan Tool V1.0.0");
    System.setProperty("java.awt.headless","true");
    JTabbedPane tabbedPane = new JTabbedPane();
    JPanel instructionRegisterTabbedPane = new JPanel() {
    public Dimension getPreferredSize() {
    Dimension size = super.getPreferredSize();
    size.width = 600;
    return size;
    tabbedPane.addTab("Instruction Register",instructionRegisterTabbedPane);
    JPanel instructionRegisterMainPanel = new JPanel();
    instructionRegisterMainPanel.setLayout( null );
    instructionRegisterMainPanel.setSize( 600,600);
    instructionRegisterMainPanel.setBorder( new EtchedBorder(Color.blue, Color.blue) );
    instructionRegisterMainPanel.setLayout(new BoxLayout(instructionRegisterMainPanel, BoxLayout.Y_AXIS));
    instructionRegisterTabbedPane.add(instructionRegisterMainPanel);
    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    getContentPane().add(tabbedPane, BorderLayout.CENTER);
    setVisible(true);
    } // end of public scanTool(String argv[]) throws IOException
    public void actionPerformed(ActionEvent e) {
    System.out.println("actionPerformed "+e);
    public static void main(String[] argv) {
    try {
    new scanTool(argv);
    } catch (IOException e) {
    System.err.println ("Caught IO Exception: " + e.getMessage());
    } // end of public class scanTool extends JFrame implements ActionListener, ItemListener

    use pack() to pack all the children before setVisible(true) or use setSize (300, 300) (whatever you want) before setVisible(true) i.e. after adding all components.
    Here is the modified code.
    import java.lang.*;
    import java.awt.datatransfer.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import java.lang.Float.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import javax.swing.table.AbstractTableModel;
    public class ScanTool extends JFrame implements ActionListener {
    public ScanTool(String argv[]) throws IOException {
    super("Vanguard Scan Tool V1.0.0");
    System.setProperty("java.awt.headless","true");
    JTabbedPane tabbedPane = new JTabbedPane();
    JPanel instructionRegisterTabbedPane = new JPanel() {
    public Dimension getPreferredSize() {
    Dimension size = super.getPreferredSize();
    size.width = 600;
    return size;
    tabbedPane.addTab("Instruction Register",instructionRegisterTabbedPane);
    JPanel instructionRegisterMainPanel = new JPanel();
    instructionRegisterMainPanel.setLayout( null );
    instructionRegisterMainPanel.setSize( 600,600);
    instructionRegisterMainPanel.setBorder( new EtchedBorder(Color.blue, Color.blue) );
    instructionRegisterMainPanel.setLayout(new BoxLayout(instructionRegisterMainPanel, BoxLayout.Y_AXIS));
    instructionRegisterTabbedPane.add(instructionRegisterMainPanel);
    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    getContentPane().add(tabbedPane, BorderLayout.CENTER);
    pack();
    setVisible(true);
    } // end of public scanTool(String argv[]) throws IOException
    public void actionPerformed(ActionEvent e) {
    System.out.println("actionPerformed "+e);
    public static void main(String[] argv) {
    try {
    new ScanTool(argv);
    } catch (IOException e) {
    System.err.println ("Caught IO Exception: " + e.getMessage());
    } // end of public class scanTool extends JFrame implements ActionListener, ItemListener
    Thanks,
    Jana

  • Fitting JPanel perfectly inside content pane of JFrame

    Say I have a JPanel with size W x H that I want to add to a JFrame such that the JFrame will be sized as small as possible while still fitting the panel inside its content pane. Is there a method in JPanel that I can overwrite or a specific method of adding to a JFrame that I can use to accomplish this, or do I need to calculate the JFrame's size with getInsets()?
    Thanks.

    If I do this...
    JFrame frame = new JFrame("Pack Test");
    JPanel panel = new JPanel();
    panel.setSize(300, 300);
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);...the resulting content pane is most definitely not 300x300 pixels. What am I doing wrong?

  • How to make content Pane on JFrame looks like Moving

    Hi guys,I have to make a Content Pane look like Race Track which is constantly moving as the cars moves forward.

    Yeah, you might want to check out SwingWorker
    http://java.sun.com/products/jfc/tsc/articles/threads/update.html
    .. and put the cars in threads.

  • Auto-stretch contents pane? Possible?

    Another customisation question if I may...
    I have a custom button on my toolbar that hides the navpane (it uses the script "javascript:showHidePane()"). My navpane has a fixed width of 200px and my contents pane has a fixed width of 760px (thats 960px in total ;-)). When the custom button is clicked and the navpane closes is there any way to make the contents pane automatically resize to the full width available (i.e. 960px) and when either the Contents, Index or Search buttons are clicked (to redisplay the navpane) the contents pane shrinks back to 760px?
    Sorry to keep posting so many obscure requests!
    Thanks
    Jonathan

    Thanks for the responses, guys!
    I'd used the ToC function before, but didn't know it would update if I told it to. I hadn't been using it because contents pages are always already included in the raw manuscripts when I set them, so I'd just been styling them, updating the numbers and moving on.
    As much as I like this (admittedly new) job, the work comes at me fast enough that I don't always have time to experiment or research better ways of doing things since there's always something else to be working on (and throwing down a quick ToC is hardly the biggest time sink). So I appreciate the pointers. I'll have to give the ToC generator another chance, as well as play with X-Refs or that script at some point if I ever have the time.
    -Calvin

  • How to add a text area in a Content pane..?

    Hi,
    I created a content pane with 5 buttons. One of them is a quit button, and I was able to create an "system.exit(0)" event handling for him. My problem is.. I have 4 other buttons, and I want them to show some text when I click them. How do I add a text area bellow my content pane..?
    Copy/paste my code to see what im talking about :) :
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Interface extends JFrame {
    public Interface() {
    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
    JButton button1 = new JButton("Test1");
    JButton button2 = new JButton("Test2");
    JButton button3 = new JButton("Test3");
    JButton button4 = new JButton("Test4");
    JButton button5 = new JButton("Quit");
    ButtonHandler handler = new ButtonHandler();
    button5.addActionListener( handler );
    contentPane.add(button1);
    contentPane.add(button2);
    contentPane.add(button3);
    contentPane.add(button4);
    contentPane.add(button5);
    contentPane.setBackground(Color.orange);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    public static void main(String args[]) {
    Interface window = new Interface();
    window.setLocation(250,350);
    window.setTitle("FlowLayout");
    window.pack();
    window.setTitle("Test");
    window.setVisible(true);
    public class ButtonHandler implements ActionListener {
    public void actionPerformed( ActionEvent e )
    System.exit(0);
    Thanks alot! :)

    By default the content pane of the JFrame uses a Border Layout. So you should:
    1) Create a JPanel
    2) Set the layout of the JPanel to FlowLayout
    3) add the buttons to the panel
    4) add the panel to the content pane
    5) add your text area to the content pane
    Read this section from the Swing tutorial on "Using Layout Managers":
    http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

  • Content pane doubt

    What exactly is the content pane and what is its purpose? I read this but am still quite confused. By the mini flow chart thing, do they mean that first i create a JFrame and then i get the contentPane for it and then i can add components like JPanel and JButton to the contentPane?
    Or can i skip the getContentPane part and directly start adding stuff like JPanel and JButtons to the JFrame? if this is true, is it preferable to do this? are there any advantages or disadvantages to doing this instead of adding components to the contentpane?
    Please help me understand this concept. Thank You.

    it's pane that contains the contents of the frame (or the rootpane, more specifically).
    You create the JFrame first.
    Then you add stuff to it's content pane. Since Java 5, you can add directly to the JFrame, and it puts things you add into the content pane for you. But it's the same thing.
    Or you can add things to your own panel, then set the panel as the content pane of the frame.
    You can't really add things to the JFrame directly without messing things up (and actually the API won't let you), cuz the rootpane is used for other things like menubars and the glasspane.

  • JFrame resizing question

    When i resize a JFrame the components it hold remain unchanged until I stop resizing the frame. Then the components conform to the frame size. Is there a way to have the components resize dynamically?

    Thank for the answer, that's exactly what I nedded!

  • Problem with content pane

    hi,
    if I have to add three different toolbars in same content pane.
    If I add these, each one of them gets overwrite over another. and only last one toolbar gets visible. please help. Also, I need the toolbar to keep top most when i dock them.

    shamail says - "I guess you didnt read the message carefully"
    late4ever says = "u can't add more than 1 toolbar on top"
    Did either of you bother to take the time to read the tutorial on "Using Layout Managers". A JToolBar is simply a component. Multiple components can be added to a container. By default the content pane uses a BorderLayout which only accepts 5 components (Center, North, South, East, West) which is why when you keep adding components to the same area you can only see the last one.
    When you create a JPanel, by default it uses a FlowLayout. When you add components they get added to the right of the previous component, which was why I gave you the sample code.
    I thought my previous answer was straight forward so I only included a piece of code. Here is a complete program you can run:
    import javax.swing.*;
    public class MultipleToolBars extends JFrame
         public MultipleToolBars(String strName)
              this.setTitle(strName);
              JPanel jp1 = new JPanel();
              JToolBar jtb1 = new JToolBar("tool1");
              JToolBar jtb2 = new JToolBar("tool2");
              JToolBar jtb3 = new JToolBar("tool3");
              JButton jb1 = new JButton("JB1");
              JButton jb2 = new JButton("JB2");
              JButton jb3 = new JButton("JB3");
              JButton jb4 = new JButton("TOOL1");
              JButton jb5 = new JButton("TOOL2");
              JButton jb6 = new JButton("TOOL3");
              JButton jb7 = new JButton("BUTTON1");
              JButton jb8 = new JButton("BUTTON1");
              JButton jb9 = new JButton("BUTTON2");
              jtb1.setFloatable(true);
              jtb2.setFloatable(true);
              jtb3.setFloatable(true);
              jtb1.add(jb1);
              jtb1.add(jb2);
              jtb1.add(jb3);
              jtb2.add(jb4);
              jtb2.add(jb5);
              jtb2.add(jb6);
              jtb3.add(jb7);
              jtb3.add(jb8);
              jtb3.add(jb9);
              jp1.add(jtb1);
              jp1.add(jtb2);
              jp1.add(jtb3);
              getContentPane().add(jp1);
         public static void main(String[] args)
              MultipleToolBars mtb = new MultipleToolBars("test");
              mtb.setSize(600, 75);
              mtb.setVisible( true );

  • Should a Status Bar be in the Root Pane or Content Pane?

    Hello, I wonder if you can help...
    Should a status bar be built into a JFrame (much like a JMenuBar, by extending JFrame and JRootPane along with its layout manager)?
    I have created a status bar using the method above, but it seems to be more complex than it need be; so I am wondering whether to simply add it to a JFrames content pane.
    Advantages of extending JRootPane and building the status bar as part of a frame:
    1. It allows the frames content panes south region to remain unoccupied, and thus will not conflict with a JToolPanes positioning.
    Advantages of adding the status bar to the content pane south region:
    1. Keeps the design nice and simple, so no knowledge of the root pane need be known;
    2. We can use composition (rather that inheritance) to define the frame and its parts.
    All comments are welcome.

    Hi,
    ( I search for iChat questions when I have finished in the iChat Forum)
    So the menu bar reads iChat, File,  Edit,  View, Buddies, Video, Window and Help
    There is no Buddy List open.
    There is no other window for iChat open.
    In the iChat Menu you only have access to Status.
    Is an item ticked in the list ?
    Is this a green (Available item) or  Red ( an Away one) ?
    Can you access the Accounts option ?  (Sitll in the iChat Menu)
    Is anything in here ticked ?
    In the Window menu any Logged in account should appear in the list  (Between the Next Chat and File Transfer items)
    It would be useful to know which version of iChat this is.
    If no account is ticked (iChat Menu > Accounts) or not showing in the Window Menu, plus you cannot determine the Status and you cannot access the Preferences then you need to access your Home Folder/Library/Preferences
    As the Library in the Home Holder is Invisible in Lion you will need the Finder's Go Menu > Go to Folder option  (you can use it in earlier OS versions if you want)
    Type in:-
    ~/Library/Preferences
    Find the file called com.apple.ichat.plist
    Drag it to the Trash and Restart iChat.
    This will lose all the settings in iChat that you have changed from Defaults but there is no way around this.
    9:23 PM      Saturday; August 27, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Content pane painting over JPopupMenu

    I have a rather complex series of overridden components (JMenuBar, JPanels, JMenus, JFrame, etc.) that I aggregate to form a 'theme frame' --- basically a 'lightweight' L&F decorated frame. The main frame is an UNDECORATED JFrame derivation, in which I basically install a derived JMenuBar class that looks and acts like the top portion of the frame's 'border' (i.e. the title bar), as well as accomodating the menu items for the frame. I then launch several of these frames from the main application, each with its own set of menus (a single top-level JMenu with a few menu items on the popup).
    My problem is this... if there are more than 1 of these frames extant after the initial start-up of the application, I can invoke the top-level menu on all of the frames, but only 1 of them actually paints it correctly... the others will show the JPopupMenu, but then the embedded content repaints AFTERWARDS, thus painting over all but the first item on the menu. What's really very bazaar is that it seems to depend totally on location of the frame on the screen (i.e. in relation to the other frames). Initially, only the top-most and/or left-most frame will paint the JPopupMenu correctly, and the rest will exhibit this "show the popup, then paint the content pane over it" behavior.
    With the help of print statements, I've been able to determine that the frame which paints the popup correctly DOES NOT get a repaint() notification on it's content-pane, whereas the others do (hence the 'cover-up' behavior of those).
    It may be useful to note that the 'content' of these frames are actually applets, which themselves have a complex set of specialized components embedded in them.
    None of the menu objects or other components involved are static to the frame class, so nothing's being shared... also, if I move one of the non-functioning windows to a different location on the screen, then the menu works fine... move it back, and the menu gets painted over again.
    I'm using JDK 1.4, JBuilder X, all components are Swing.
    Any help, please??????
    XNHillBilly

    That did the trick! I had a gut feeling it was something simple like that... I still don't fully understand exactly what was going on (why one frame would paint fine, while the others wouldn't), but that's less important than having it work correctly at this point ;-)
    Thanks mucho rykk,
    XNHillBilly

  • Clear content pane problems

    can anyone tell why can't I clear the content pane in the following code or a method to achieve this thing?
    thank you.
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package librabrymanagementf;
    import java.awt.event.ActionEvent;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import javax.swing.SwingUtilities;
    import java.io.*;
    import java.io.File;
    import java.lang.Object;
    * @author emi
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) {
                  // Creates a model of the system logic.
            libraryModel model = new libraryModel();
            // Creaties a view for the system logic.
            libraryView view = new libraryView();
            // Creates a controller that links the two.
            libraryController controller = new libraryController(model, view);
      class libraryModel{
       public void addToFile(String title, String author, String ID){
       try{   
        FileWriter fw= new FileWriter("file.txt",true);
        fw.write(title+"\t"+author+"\t"+ID);
        fw.write("\r\n");
        fw.close();}
        catch (IOException e)
                   System.err.println ("Unable to write to file");
                   System.exit(-1);
      class libraryView{
          libraryModel model= new libraryModel();
         JFrame frame = new JFrame("[=] JMenuBar [=]");
        JMenuItem addBook = new JMenuItem("Add Book");
        JMenuItem deleteBook = new JMenuItem("Delete Book");
        JMenu modifyBook = new JMenu("Modify Book");
        JMenuItem modifyByTitle = new JMenuItem("Modify by Title");
        JMenuItem modifyByAuthor = new JMenuItem("Modify by Author");
        JMenu searchBook = new JMenu("Search Book");
        JMenuItem searchByTitle = new JMenuItem("Search by Title");
        JMenuItem searchByAuthor = new JMenuItem("Search by Author");
        JMenuItem searchByID = new JMenuItem("Search by ID");
        JMenuItem bookListing = new JMenuItem("Book Listing");
        JMenuBar menuBar = new JMenuBar();
        JMenu menu = new JMenu("Options");
        JPanel panel;
        JPanel textPanel, panelForTextFields, completionPanel;
        JLabel titleLabel, authorLabel, IDLabel, bookTitleLabel, passLabel;
        JTextField bookTitleField, authorField, IDField;
        JButton loginButton;
    public libraryView(){
         createAndShowGUI();
    public void CreateMenuBar()
          menuBar.add(menu);
          menu.add(addBook);
          menu.add(deleteBook);
          modifyBook.add(modifyByTitle);
          modifyBook.add(modifyByAuthor);
          menu.add(modifyBook);
          searchBook.add(searchByTitle);
          searchBook.add(searchByAuthor);
          searchBook.add(searchByID);
          menu.add(searchBook);
          menu.add(bookListing);
          frame.setJMenuBar(menuBar);
       public void createAndShowGUI(){
          frame.setSize(400,400);
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          CreateMenuBar();
       public void addBookForm(){
            JPanel panel = new JPanel();
            clear(panel);
            panel.setLayout(null);
            titleLabel = new JLabel("Add Book");
            titleLabel.setLocation(0,0);
            titleLabel.setSize(290, 30);
            titleLabel.setHorizontalAlignment(0);
            panel.add(titleLabel);
            // Creation of a Panel to contain the JLabels
            textPanel = new JPanel();
            textPanel.setLayout(null);
            textPanel.setLocation(10, 35);
            textPanel.setSize(70, 150);
            panel.add(textPanel);
            // Book title Label
            bookTitleLabel = new JLabel("Title");
            bookTitleLabel.setLocation(0, 0);
            bookTitleLabel.setSize(70, 40);
            bookTitleLabel.setHorizontalAlignment(4);
            textPanel.add(bookTitleLabel);
          // Book author Label
            authorLabel = new JLabel("Author");
            authorLabel.setLocation(0, 40);
            authorLabel.setSize(70, 40);
            authorLabel.setHorizontalAlignment(4);
            textPanel.add(authorLabel);
             // Book ID Label
            IDLabel = new JLabel("ID");
            IDLabel.setLocation(0, 80);
            IDLabel.setSize(70, 40);
            IDLabel.setHorizontalAlignment(4);
            textPanel.add(IDLabel);
             // TextFields Panel Container
            panelForTextFields = new JPanel();
            panelForTextFields.setLayout(null);
            panelForTextFields.setLocation(110, 47);
            panelForTextFields.setSize(200, 130);
            panel.add(panelForTextFields);
            // book title Textfield
            bookTitleField = new JTextField(8);
            bookTitleField.setLocation(0, 0);
            bookTitleField.setSize(200, 20);
            panelForTextFields.add(bookTitleField);
            // book author Textfield
            authorField = new JTextField(8);
            authorField.setLocation(0, 40);
            authorField.setSize(200, 20);
            panelForTextFields.add(authorField);
            //book id Textfield
            IDField = new JTextField(8);
            IDField.setLocation(0, 80);
            IDField.setSize(200,20);
            panelForTextFields.add(IDField);
             // Button for Submit
            loginButton = new JButton("Submit");
            loginButton.setLocation(170, 180);
            loginButton.setSize(80, 20);
            loginButton.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
                     String bookTitle = bookTitleField.getText().trim();
                     String bookAuthor = authorField.getText().trim();
                     String bookID = IDField.getText().trim();
                     int intBookID = Integer.parseInt(bookID);
                     model.addToFile(bookTitle, bookAuthor, bookID);
            panel.add(loginButton);
            panel.setOpaque(true);   
            frame.getContentPane().add(panel, BorderLayout.CENTER);
            frame.setVisible(true);
              clear(panel);
       public void deleteBookForm(){
            JPanel panel = new JPanel();
            panel.setLayout(null);
            titleLabel = new JLabel("Delete Book");
            titleLabel.setLocation(0,0);
            titleLabel.setSize(290, 30);
            titleLabel.setHorizontalAlignment(0);
            panel.add(titleLabel);
             panel.setOpaque(true);   
             frame.getContentPane().add(panel, BorderLayout.CENTER);
            frame.setVisible(true);
        clear(panel);
       public void clear(JPanel panel){
           panel.removeAll();
           panel.validate();
        public void MenuActionListeners(ActionListener al) {
            addBook.setActionCommand("addBook");
            addBook.addActionListener(al);
            deleteBook.setActionCommand("deleteBook");
            deleteBook.addActionListener(al);
            modifyByTitle.setActionCommand("modifyByTitle");
            modifyByTitle.addActionListener(al);
            modifyByAuthor.setActionCommand("modifyByAuthor");
            modifyByAuthor.addActionListener(al);
            searchByTitle.setActionCommand("searchByTitle");
            searchByTitle.addActionListener(al);
            searchByAuthor.setActionCommand("searchByAuthor");
            searchByAuthor.addActionListener(al);
            searchByID.setActionCommand("searchByID");
            searchByID.addActionListener(al);
            bookListing.setActionCommand("bookListing");
            bookListing.addActionListener(al);
    class libraryController implements ActionListener{
         libraryModel model;
         libraryView view;
       public libraryController (libraryModel model, libraryView view) {
            this.model = model;
            this.view  = view;
          //  this.view.init_view();
            view.MenuActionListeners(this);
         //   view.addBookListeners(this);
       public void actionPerformed(ActionEvent ae)
        String action_com = ae.getActionCommand();
            if (action_com.equals("addBook")){
            // view.clear();
             view.addBookForm();
            else if (action_com.equals("deleteBook")){
          //  view.clear();
            view.deleteBookForm();
            System.out.println("kk");
            else if (action_com.equals("modifyByTitle")){
                 System.out.println(action_com);
            else if (action_com.equals("modifyByAuthor")){
                 System.out.println(action_com);
            else if (action_com.equals("searchByTitle")){
                 System.out.println(action_com);
            else if (action_com.equals("searchByAuthor")){
                 System.out.println(action_com);
            else if (action_com.equals("searchByID")){
                 System.out.println(action_com);
            else if (action_com.equals("bookListing")){
                 System.out.println(action_com);
        Thanks!

    Please pare down your code to a manageable amount. You don't need 3/4 of that code to demonstrate your problem, so why should you ask us to read it??

  • Content Pane Question

    I've noticed that there seem to be two common ways in which a Content Pane is defined. I've included examples of each below and am interested in whether there's any reason that either might be preferable to use over the other.
    Thanks very much.
    EXAMPLE 1 _______________________________
    public static void main(String[] args) {   
    VPA vpa = new VPA();
    JFrame frame = new JFrame("VPA");
    frame.setContentPane(vpa.contentPanel);
    public VPA() {
    contentPanel = new JPanel();
    EXAMPLE 2 ______________________________________
    public static void main(String[] args) {     
    VPA vpa = new VPA();
    public class OtherClass extends JFrame {
    public OtherClass() {
    Container contentPane = getContentPane();
    }

    I usually create my own content pane then add it to the frame like this:
    public class test extends JFrame{
        public test{
         JPanel contentPane = new JPanel();
         //add stuff to contentPane
         setContentPane(contentPane);
    }When working with frames and swing, JPanel is usually your base content pane. Also, your first code example will not work, don't bother working with it. My example is closest to the second one.

  • Multiscreen HTML 5  output  in Chrome – when scrolling down very long topics in the content pane the navigation area 'moves up' , i.e cant see search field or TOC.

    Hi,
    Multiscreen HTML 5  output  in Chrome – when scrolling down very long topics in the content pane the navigation area 'moves up' , i.e cant see search field or TOC.
    thanks
    Anat 

    This is by design. If you want to change this, the content section must have a set height and scroll. Which layout are you using? -- Check out the Responsive layouts and the Social layout. I believe those have the more traditional TOC placement.
    Kind regards,
    Willam

  • Continuous layout on JFrame resize?

    hi,
    on my machine (win2k) when you resize a JFrame with the mouse, the contents are not resized until you have released the drag. Is this a property of my java/OS settings or a limitation of Swing?
    JSplitPane has a setContinuousLayout method which sounds like it does something similar?
    thanks,
    asjf

    Component and Window listeners are not going to work since the window resize is not happening on the AWT thread.. So, you do need your own thread to monitor the size of the window, and invalidate/validate your window if the size changes. The following should work for you, coded as a method in a utility class so it can be easily reused by any JFrame:
         private static Map continuousLayoutWindows;
         * Sets the specified frame to do a continuous layout, so that if the user resizes the frame,
         * the components within the frame are resized as well.
         * @param frame JFrame
         public static void setContinuousLayout(final JFrame frame) {
              new Timer(100, new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        Dimension currentSize = frame.getSize();
                        if (continuousLayoutWindows == null) {
                             continuousLayoutWindows = new HashMap();
                        Dimension windowSize = (Dimension)continuousLayoutWindows.get(frame);
                        if (windowSize == null) {
                             windowSize = new Dimension();
                             continuousLayoutWindows.put(frame, windowSize);
                        if (!currentSize.equals(windowSize)) {
                             windowSize.width = currentSize.width;
                             windowSize.height = currentSize.height;
                             SwingUtilities.invokeLater(new Runnable() {
                                  public void run() {
                                       frame.invalidate();
                                       frame.validate();
                                       frame.repaint();
              }).start();

Maybe you are looking for