JPanel not displaying components

i am working on a simple html renderer- at the moment all i am trying to do is to add JTextPane components to two different JPanels (search and content). I can add the text panes to the search bar, however none of the components are displayed in the content panel. I get no compile time errors, im really at a loss as to what the problem could be.
this is the code im using-
public class Demo extends JFrame
    private JPanel search, content;
    private JSplitPane splitPane;
    //private ArrayList<JTextPane> textCollection;
    //private ArrayList<JTextPane> preCollection;
    //specifies the universal font size the content JPanel
    private final int fontSize = 18;
    //specifies the universal font size for the search JPanel
    private final int searchFontSize = 9;
    /** Creates a new instance of Main */
    public Demo()
      this.setTitle("DEMO!");
      this.setDefaultCloseOperation(EXIT_ON_CLOSE);
      //sets default size
      this.setSize(500, 500);
      //init panel controls- these will hold all rendered controls
      search = new JPanel();
      //use BoxLayout to ensure controls are positioned correctly
      search.setLayout(new BoxLayout(search, BoxLayout.Y_AXIS));
      search.setBackground(Color.white);
      content = new JPanel();
      content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
      content.setBackground(Color.white);
      //init JScrollPanes for both containers- allows for scrolling content of unlimited width/length
      JScrollPane contentScroller = new JScrollPane(content);
      JScrollPane searchScroller = new JScrollPane(search);
      //create a split pane container to contain both scroll panes
      splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, searchScroller, contentScroller);
      //search bar recieves 25% of screen size
      splitPane.setDividerLocation(this.getWidth() / 4);
      this.getContentPane().add(splitPane);
      //show controls
      this.setVisible(true);
    * Creates a new text component- text contained will be line wrapped as the user resizes the JFrame
    public void newText(String text)
      //init properites of new JTextPane
      JTextPane tp = newTextPane(text);
      tp.setBackground(Color.blue);
      //line wrap add to content panel
      tp.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
      tp = getLines(tp, this.getWidth() - splitPane.getDividerLocation());
      content.add(tp);
      //resize text for search panel, line wrap and add to search panel
      tp.setFont(new Font("Times New Roman", Font.PLAIN, searchFontSize));
      tp = getLines(tp, splitPane.getDividerLocation());
      search.add(tp);
    * Creates a new preformated text component- this will not be line wrapped
    public void newPre(String preformattedContent)
        JTextPane tp = newTextPane(preformattedContent);
        tp.setBackground(Color.red);
        //add to content panel
        tp.setFont(new Font("Courier New", Font.PLAIN, fontSize));
        content.add(tp);
        //resize text for search panel and add to search panel
        tp.setFont(new Font("Courier New", Font.PLAIN, searchFontSize));
        search.add(tp);
    * Small method that init's a JTextPane component with common properites used by the newText/Pre methods
    private JTextPane newTextPane(String s)
      JTextPane tp = new JTextPane();
      //set text
      tp.setText(s);
      //may not be editied
      tp.setEditable(false);
      //align correctly
      tp.setAlignmentY(Component.TOP_ALIGNMENT);
      tp.setAlignmentX(Component.LEFT_ALIGNMENT);
      //set maximum size to preferred size, this makes sure the JTextComponent will not "stretch" when the JFrame is resized drastically
      tp.setMaximumSize(tp.getPreferredSize());
      return tp;
    * Sets the appropriate preferred height & width of a given JTextPanel, essentially word wrapping any text contained within
    private JTextPane getLines(JTextPane tp, int paneSize)
      //get preferred size of the text panel - this is the smallest size the text panel may be and still visibly display its text content
      Dimension d = tp.getPreferredSize();
      double prefWidth = d.getWidth();
      double prefHeight = d.getHeight();
      //factor will determine if line wrapping is required
      double factor = prefWidth / (double) paneSize;
      //if factor is greater than 1, the preferred width is greater than the size available in the pane
      if (factor >= 1){
        //set width so that it matches the size available on the screen
        d.setSize((double) this.getWidth() - paneSize, factor * prefHeight);
        tp.setMaximumSize(d);
        tp.setPreferredSize(d);
      //else- do nothing! resizing is not required
      return tp;
     * @param args the command line arguments
    public static void main(String[] args)
      Demo d = new Demo();
      d.newText("this is some content ooh look content i hope this is long enough to test the wrapp esfsdfsdf sdf sdfsdfsd fsdf sdfsdfsdfd sfsdf sdfsdxf sdf sdf sdfsd fsd fsdf ing");
      d.newPre("a     pre          formatted           lump of    =  text! !  !");
    public void paint(Graphics g)
        super.paint(g);
        System.out.println("update called");
        //preferred.setSize(this.getWidth() - (this.getWidth() / 4), this.getHeight());
        //max.setSize(this.getWidth(), this.getHeight());
}

Do you need to keep adding JTextPane's to the content and search panes or do you just need to append text to the existing panes?
If the later, you may want to create the JTextPanes in the constructor and use a set method to append/edit/remove text. As follows:
import javax.swing.*;
import java.awt.*;
public class Demo extends JFrame
    private JPanel search, content;
    private JSplitPane splitPane;
    private JTextPane contentTextPane;
    private  JTextPane searchTextPane;
    //private ArrayList<JTextPane> textCollection;
    //private ArrayList<JTextPane> preCollection;
    //specifies the universal font size the content JPanel
    private final int fontSize = 18;
    //specifies the universal font size for the search JPanel
    private final int searchFontSize = 9;
    /** Creates a new instance of Main */
    public Demo()
      this.setTitle("DEMO!");
      this.setDefaultCloseOperation(EXIT_ON_CLOSE);
      //sets default size
      this.setSize(500, 500);
      //init panel controls- these will hold all rendered controls
      search = new JPanel();
      //use BoxLayout to ensure controls are positioned correctly
      search.setLayout(new BoxLayout(search, BoxLayout.Y_AXIS));
      search.setBackground(Color.white);
      content = new JPanel();
      content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
      content.setBackground(Color.white);
      //init JScrollPanes for both containers- allows for scrolling content of unlimited width/length
      JScrollPane contentScroller = new JScrollPane(content);
      JScrollPane searchScroller = new JScrollPane(search);
      //create a split pane container to contain both scroll panes
      splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, searchScroller, contentScroller);
      //search bar recieves 25% of screen size
      splitPane.setDividerLocation(this.getWidth() / 4);
      /*add the textpanes to the JPanels*/
      contentTextPane = new JTextPane();
      content.add(contentTextPane);
      searchTextPane = new JTextPane();
      search.add(searchTextPane);
      this.getContentPane().add(splitPane);
      //show controls
      this.setVisible(true);
    * Creates a new text component- text contained will be line wrapped as the user resizes the JFrame
    public void newText(String text)
      //init properites of new JTextPane
      JTextPane tp = newTextPane(text);
      tp.setBackground(Color.blue);
      //line wrap add to content panel
      tp.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
      tp = getLines(tp, this.getWidth() - splitPane.getDividerLocation());
      content.add(tp);
      //resize text for search panel, line wrap and add to search panel
      tp.setFont(new Font("Times New Roman", Font.PLAIN, searchFontSize));
      tp = getLines(tp, splitPane.getDividerLocation());
      search.add(tp);
    public void addToContent(String text){
         contentTextPane.setText(text);
    * Creates a new preformated text component- this will not be line wrapped
    public void newPre(String preformattedContent)
        JTextPane tp = newTextPane(preformattedContent);
        tp.setBackground(Color.red);
        //add to content panel
        tp.setFont(new Font("Courier New", Font.PLAIN, fontSize));
        content.add(tp);
        //resize text for search panel and add to search panel
        tp.setFont(new Font("Courier New", Font.PLAIN, searchFontSize));
        search.add(tp);
    * Small method that init's a JTextPane component with common properites used by the newText/Pre methods
    private JTextPane newTextPane(String s)
      JTextPane tp = new JTextPane();
      //set text
      tp.setText(s);
      //may not be editied
      tp.setEditable(false);
      //align correctly
      tp.setAlignmentY(Component.TOP_ALIGNMENT);
      tp.setAlignmentX(Component.LEFT_ALIGNMENT);
      //set maximum size to preferred size, this makes sure the JTextComponent will not "stretch" when the JFrame is resized drastically
      tp.setMaximumSize(tp.getPreferredSize());
      return tp;
    * Sets the appropriate preferred height & width of a given JTextPanel, essentially word wrapping any text contained within
    private JTextPane getLines(JTextPane tp, int paneSize)
      //get preferred size of the text panel - this is the smallest size the text panel may be and still visibly display its text content
      Dimension d = tp.getPreferredSize();
      double prefWidth = d.getWidth();
      double prefHeight = d.getHeight();
      //factor will determine if line wrapping is required
      double factor = prefWidth / (double) paneSize;
      //if factor is greater than 1, the preferred width is greater than the size available in the pane
      if (factor >= 1){
        //set width so that it matches the size available on the screen
        d.setSize((double) this.getWidth() - paneSize, factor * prefHeight);
        tp.setMaximumSize(d);
        tp.setPreferredSize(d);
      //else- do nothing! resizing is not required
      return tp;
     * @param args the command line arguments
    public static void main(String[] args)
      Demo d = new Demo();
      d.newText("this is some content ooh look content i hope this is long enough to test the wrapp esfsdfsdf sdf sdfsdfsd fsdf sdfsdfsdfd sfsdf sdfsdxf sdf sdf sdfsd fsd fsdf ing");
      d.newPre("a     pre          formatted           lump of    =  text! !  !");
      d.addToContent("testing the content panel");
    public void paint(Graphics g)
        super.paint(g);
        System.out.println("update called");
        //preferred.setSize(this.getWidth() - (this.getWidth() / 4), this.getHeight());
        //max.setSize(this.getWidth(), this.getHeight());
}If this is not the case let me know and Ill take another look. ;-)

Similar Messages

  • JPanel not displaying in Windows

    I have a window displaying a panel and some buttons. I installed the application on Solaris and Windows. On Solaris, it displays fine every time. On Widows, it displays the first time I bring up the application but the panel does not display when I close it and bring it back up. Has anyone seen this before. I've put some debugging statements in, but I have no idea where to start looking.
    Thanks,
    Josh

    Here is the code that sets up the panel:
    // Initialize and GUI implementation
    private void jbInit() throws Exception {
    try{
    logger.fine("AudioEditPanel jbInit");
    this.setLayout(new BorderLayout());
    m_audioIcon = new ImageIcon(dataDir + File.separator + m_sAlertIcon);
    TitledBorder curSettingBorder = new TitledBorder(m_sCurSetting);
    TitledBorder soundBorder = new TitledBorder(m_sSound);
    m_editPanel.setLayout(new BorderLayout());
    // Create "Restore Default" button
    m_defaultButton.setText("Restore Default");
    m_defaultButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         defaultButton_actionPerformed(e);
    m_currentPanel.setLayout(new BorderLayout());
    m_currentPanel.setBorder(curSettingBorder);
    m_currentPanel.setPreferredSize(new Dimension(155, 165));
    // Create customized tabel model
    AudioTableModel tableModel = new AudioTableModel();
    curTable = new JTable(tableModel);
    //Set up column sizes.
    initColumnSizes(curTable, tableModel);
    // Only allows single selection
    curTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    curTable.setBorder(BorderFactory.createLoweredBevelBorder());
    curTable.setColumnSelectionAllowed(false);
    curTable.getTableHeader().setReorderingAllowed(false);
    setUpWavEditor(curTable);
    //Fiddle with the Preview column's cell editors/renderers.
    setUpPreviewColumn(curTable.getColumnModel().getColumn(preview_column));
    // Add filter for the File Choose, so only Sound (*.wav) file
    // can be used.
    fc.addChoosableFileFilter(new WavFilter());
    fc.setAcceptAllFileFilterUsed(false);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (m_sDesDir != "") {
    File wav_dir = new File(m_sDesDir);
    fc.setCurrentDirectory(wav_dir);
    fc.setDialogTitle("List of audio files");
    m_assignPanel.setLayout(gridBagLayout1);
    m_assignPanel.setBorder(soundBorder);
    // "Selected Sound" label
    SelectSoundLabel.setFont(new java.awt.Font("Dialog", 0, 10));
    SelectSoundLabel.setForeground(Color.black);
    SelectSoundLabel.setText("Selected Sound:");
    //Click Browse button will pop up file chooser
    browseButton.setActionCommand("Browse");
    browseButton.setText("Browse");
    browseButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         browseButton_actionPerformed(e);
    //Click preview button will play the sound defined in the sound text area
    previewButton.setIcon(m_audioIcon);
    previewButton.setMargin(new Insets(0, 0, 0, 0));
    previewButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         previewButton_actionPerformed(e);
    // selected sound text field.
    sSoundText.setBorder(BorderFactory.createLoweredBevelBorder());
    sSoundText.addActionListener(new ActionListener() {
    public void actionPerformed (ActionEvent e) {
    sSoundText_actionPerformed(e);
    // "Preview" label
    previewTextArea.setFont(new java.awt.Font("Dialog", 0, 10));
    previewTextArea.setText("Preview");
    previewTextArea.setForeground(Color.black);
    // Use GridBag layout to put the components in the proper position
    m_defaultPanel.add(m_defaultButton, BorderLayout.CENTER);
    m_editPanel.add(m_assignPanel, BorderLayout.SOUTH);
    m_assignPanel.add(browseButton, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 2, 0));
    m_assignPanel.add(previewButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 2));
    m_assignPanel.add(previewTextArea, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    m_assignPanel.add(sSoundText, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 3), 257, 2));
    m_assignPanel.add(SelectSoundLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 0, 6, 0), 6, 0));
    m_curScrollPanel.getViewport().add(curTable, BorderLayout.CENTER);
    m_currentPanel.add(m_curScrollPanel, BorderLayout.CENTER);
    m_currentPanel.add(m_defaultPanel, BorderLayout.SOUTH);
    m_editPanel.add(m_currentPanel, BorderLayout.NORTH);
    m_tabbedPane.addTab(m_sAudioSetting, m_editPanel);
    this.add(m_tabbedPane, BorderLayout.CENTER);
    checkAudioPrefs();
    }catch(Exception e){
    e.printStackTrace();
    System.out.println(e.getMessage());
    }

  • Jpanel not displaying

    i have 2 Jpanels and at the click of a button, "a" should show up and "B" should be removed and call the validate method .now if i click another button the reverse should happen .but the panel does not show until i move my mouse on it .
    please what can i do?

    I think CardLayout is the better choice.
    Add both panels to a component which uses the CardLayout manager, which you initialized as private member like
    this.localCardLayout = new CardLayout();
    this.setLayout(localCardLayout);
    this.add(identifierPanelA, panelA);
    this.add(identifierPanelB, panelB);where panelA and panelB are your panels and identifierPanelA and identifierPanelB are two different strings.
    Initially this will show panelA, you can easily switch to panelB by calling the following method:
    this.localCardLayout.show(this,identifierPanelB);

  • JPanel not sharing components

    Hi,
    I am creating a number of components(JLabel,JTextField) and using them in 2 different JPanel. But, as soon as I try to make the JPanels share the same components(sharedLabel), only the last JPanel gets the shared component. Why there is no sharing?
    relevant code:
         JLabel sharedLabel = new JLabel("Model:")
         addUsedCarPanel = new JPanel();
         addUsedCarPanel.add(sharedLabel);
         addNewCarPanel = new JPanel();
         addNewCarPanel.add(sharedLabel);
    I will appreciate your reply.
         

    Hello,
    you can't share components the way you try. Swing's gui components are ordered hierachically in a tree like manner. Any swing component has an unique parent component.
    In your case you must actually create two labels with the same text and add them to your two panels.
    However what is actually possible is model sharing. I.e. two different JTables can show the same data (data from the same model).

  • RegionRenderer encodeAll The region component with id: pt1:r1 has detected a page fragment with multiple root components. Fragments with more than one root component may not display correctly in a region and may have a negative impact on performance.

    Hi,
    I am using JDEV 11.1.2.1.0
    I am getting the following error :-
    <RegionRenderer> <encodeAll> The region component with id: pt1:r1 has detected a page fragment with multiple root components. Fragments with more than one root component may not display correctly in a region and may have a negative impact on performance. It is recommended that you restructure the page fragment to have a single root component.
    Piece of code is for region is:-
       <f:facet name="second">
                                                <af:panelStretchLayout id="pa1"
                                                                       binding="#{backingBeanScope.Assign.pa1}">
                                                    <f:facet name="center">
                                                        <af:region value="#{bindings.tfdAssignGraph1.regionModel}" id="r1"
                                                                   binding="#{backingBeanScope.Assign.r1}"/>
                                                    </f:facet>
                                                </af:panelStretchLayout>
                                            </f:facet>
    How do I resolve it ?
    Thanks,

    Hi,
    I see at least 3 errors
    1. <RegionRenderer> <encodeAll> The region component with id: pt1:r1 has detected a page fragment with multiple root components.
    the page fragment should only have a single component under the jsp:root tag. If you see more than one, wrap them in e.g. an af:panelGroupLayout or af:group component
    2. SAPFunction.jspx/.xml" has an invalid character ".".
    check the document (you can open it in JDeveloper if the customization was a seeded one. Seems that editing this file smething has gone bad
    3. The expression "#{bindings..regionModel}" (that was specified for the RegionModel "value" attribute of the region component with id "pePanel") evaluated to null.
    "pageeditorpanel" does seem to be missing in the PageDef file of the page holding the region
    Frank

  • Text not displaying on components

    I have one swf file where im using the default textInput and
    button components. Just so the user can enter a zip code and click
    submit. When i publish that swf, everything looks fine. The problem
    is that i am loading that swf into a master swf and when i view it
    through the master swf, it displays the components without text.
    The submit button is blank, it should say 'submit' on it, and no
    characters display when you type into the textInput component. I am
    able to type characters and submit the form, but i can't see what
    im typing. I've tried messing with embedding fonts in the child swf
    as well as the master to no avail. If anyone has any suggestions,
    they would be greatly appreciated.

    Here's how to talk to your dynamic text box. Where you put
    this bit depends
    on how you are building the preloader, but since you say the
    progress bar
    works fine, I'll assume you know what you're doing there and
    will be able to
    get this in the right spot.
    // variable that calculates a number for the percent loaded
    preloaded = Math.floor((loadedBytes/totalBytes)*100);
    // this line is talking to a dynamic text box named
    "percentage_txt" that is
    inside a movieClip named "preloader_mc" on the root timeline
    // depending on your setup the path may be different, but
    make sure
    everything on the way to the text box is named
    _root.preloader_mc.percentage_txt.text = preloaded + "%";
    // You've probably left out the ".text = " bit. Just a guess,
    but that's
    the bit I always find
    // I've left out when I'm having trouble with dynamic text.
    // Also make sure your text color is not set to the same
    color as your
    background. Duh.
    Good luck.
    --KB
    "patbegg" <[email protected]> wrote in
    message
    news:ejuu12$bmd$[email protected]..
    > Hi,
    > Cheeky little problem. I cannot get the dynamix text to
    show on the
    > preloader
    > of a loaded movie. I am calling in a .swf which has a
    preloader in it, the
    > progress bar is fine but the text showing the percent
    will not display.
    >
    > I have tried the _lockroot method, but no joy. Any ideas
    anyone?
    >
    > Any help appreciated guys.
    >
    > Cheers,
    > Pat
    >

  • ADF components do not display Chinese simplified (showing English instead)

    Dear All
    I am having a problem getting ADF components to display in Chinese simplified language. Buttons display in Chinese correctly however components such as: < af:table > (the previous and next values do not display in Chinese, again in English only).
    I have tried it under Japanese and these components show Japanese.
    Any ideas on what the problem may be caused by would be greatly appreciated.
    Best regards
    Andrew Och

    Actually I found the problem.
    It seems that the language resource bundle has the incorrect name. Renaming:
    oracle.adfinternal.view.faces.ui.laf.oracle.desktop.resource.BLAFBundle_zh_CN.java
    to
    oracle.adfinternal.view.faces.ui.laf.oracle.desktop.resource.BLAFBundle_zh.java
    resolved my problem.

  • A Components not displayed in JDialog opened from Applet.

    Hi. I have an Applet from which I am opening a JDialog, that contains a JPanel with some JTextFields. Sometimes half of textfields are not displayed. Does anybody know something about such problem?

    When you say sometimes do you mean sometimes or do
    you mean all the time?sometimes.
    In general when you have a condition that only
    sometimes occurs this is the result of a race
    condition. Assuming that this is something you see
    only sometimes, my guess is that you are displaying
    the dialog (calling setVisible(true)) before you have
    finished adding all the componentsYep. you are 100% right. found it. it was not synchronized lazy initialization called from some callbacks in different threads. ;)

  • Adding and displaying a new JPanel -- not working as expected

    I'm starting my own new thread that is based on a problem discussed in another person's thread that can be found here in the New to Java forum titled "ActionListener:
    http://forum.java.sun.com/thread.jspa?threadID=5207301
    What I want to do: press a button which adds a new panel into another panel (the parentPane), and display the changes. The Actionlistener-derived class (AddPaneAction) for the button is in it's own file (it's not an internal class), and I pass a reference to the parentPane in the AddPaneAction's constructor as a parameter argument.
    What works: After the button is clicked the AddPaneAction's actionPerformed method is called without problem.
    What doesn't work: The new JPanel (called bluePanel) is not displayed as I thought it would be after I call
            parentPane.revalidate();  // this doesn't work
            parentPane.repaint(); 
    What also doesn't work: So I obtained a reference to the main app's JFrame (I called it myFrame) by recursively calling component.getParent( ), no problem there, and then tried (and failed to show the bluePanel with) this:
            myFrame.invalidate();  // I tried this with and without calling this method here
            myFrame.validate();  // I tried this with and without calling this method here
            myFrame.repaint();
    What finally works but confuses me: I got it to work but only after calling this:
            myFrame.pack(); 
            myFrame.repaint();But I didn't think that I needed to call pack to display the panel. So, what am I doing wrong? Why are my expectations not correct? Here's my complete code/SSCCE below. Many thanks in advance.
    Pete
    The ParentPane class:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class ParentPane extends JPanel
        private JButton addPaneBtn = new JButton("Add new Pane");
        public ParentPane()
            super();
            setLayout(new BorderLayout());
            setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            setBackground(Color.yellow);
            JPanel northPane = new JPanel();
            northPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            northPane.setBackground(Color.yellow);
            northPane.add(addPaneBtn);
            add(northPane, BorderLayout.NORTH);
            // add our actionlistener object and pass it a reference
            // to the main class which happens to be a JPanel (this)
            addPaneBtn.addActionListener(new AddPaneAction(this));
        public static void main(String[] args)
            javax.swing.SwingUtilities.invokeLater(new Runnable()
                public void run()
                    createAndShowGUI();
        private static void createAndShowGUI()
            JFrame frame = new JFrame("test add panel");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(new ParentPane());
            frame.pack();
            frame.setVisible(true);
    } the AddPaneAction class:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingConstants;
    public class AddPaneAction implements ActionListener
        private JPanel parentPane;
        private JFrame myFrame;
        public AddPaneAction(JPanel parentPane)
            this.parentPane = parentPane;
         * recursively get the JFrame that holds the parentPane panel.
        private JFrame getJFrame(Component comp)
            Component parentComponent = comp.getParent();
            if (parentComponent instanceof JFrame)
                return (JFrame)parentComponent;
            else
                return getJFrame(parentComponent);
        public void actionPerformed(ActionEvent arg0)
            JPanel bluePanel = new JPanel(new BorderLayout());
            bluePanel.setBackground(Color.blue);
            bluePanel.setPreferredSize(new Dimension(400, 300));
            JLabel myLabel = new JLabel("blue panel label");
            myLabel.setForeground(Color.LIGHT_GRAY);
            myLabel.setVerticalAlignment(SwingConstants.CENTER);
            myLabel.setHorizontalAlignment(SwingConstants.CENTER);
            bluePanel.add(myLabel, BorderLayout.CENTER);
            parentPane.add(bluePanel);
            myFrame = getJFrame(parentPane);
            //parentPane.revalidate();  // this doesn't work
            //parentPane.repaint(); 
            //myFrame.invalidate(); // and also this doesn't work
            //myFrame.validate();
            //myFrame.repaint();
            myFrame.pack();  // but this does!?
            myFrame.repaint();
    }

    For me (as it happens I'm using JDK 1.5.0_04) your code appears to work fine.
    It may be that we're seeing the same thing but interpreting it differently.
    1. When I run your application with your "working" code, and press the button then the JFrame resizes and the blue area appears.
    2. When I run your application with your "not working" code and press the button then the JFrame does not resize. If I manually resize it then the blue area is there.
    3. When I run your application with your "not working" code, resize it first and then press the button then the JFrame then the blue area is there.
    I interpret all of this as correct behaviour.
    Is this what you are seeing too?
    Are you expecting revalidate, repaint, invalidate or validate to resize your JFrame? I do not.
    As an aside, I do remember having problems with this kind of thing in earlier JVMs (e.g. various 1.2 and 1.3), but I haven't used it enough recently to know if your code would manifest one of the previous problems or not. Also I don't know if they've fixed any stuff in this area.

  • Images in wwv_flow_file_objects$  do not display in the shared components

    Recently I needed to re-create an APEX workspace. The schema was intact, so I just created a new APEX workspace mapped to that schema and re-imported my apps.
    All was well EXCEPT that the images and files (e.g. style sheets) previously uploaded to the database under the original workspace were missing. Looking at the wwv_flow_file_objects$ table I saw the images and files were present but their security ID did not match that of the new APEX workspace.
    I updated the security ID and the files and images now work BUT THEY DO NOT DISPLAY IN THE SHARED COMPONENT LISTINGS. My fear is that I'll try to upload an image or file by the same name and they'll stop working because there will then be two rows in wwv_flow_file_objects$ with the same file name and security ID.
    Does anyone know how to get these items to display properly in the shared component reports?

    If they were application-specific, you would need to ensure that the new flow_id value in the table matched that of the application to which the file should be associated. If not, that value should be zero.
    Scott

  • Problem with Loader Components, can not display my forms properly

    Here is the problem (my God, my customer waiting for his web
    site:( ... ) I have a form made in CoffeeCup Flash Form Builder
    (Nice one...).Now this form with fields like name, sec name age,
    etc I want it to apear into my main screen when I press the button
    "Reservation" and then the customer could fill the fields and sent
    it to my mail. I tryed with the Loader Component, I mean when I
    press the button then starts "playing" the form.swf. BUT the Loader
    can not display the form properly specialy thinks like drop down
    menus in the form, or check boxes....It just show me the
    form....The Flash Form Builder gives me 4 files like: form.swf,
    form.html, form.php and form.xml. Any solution on how my customers
    complete this form with no problems?
    THANK YOU A LOT!

    Dear,
    You have to following these step to run form on firefox,
    Run the following file,
    1) C:\DevSuiteHome_1\jinit\jinit.exe
    2) jvm.dll copy this file to the following path,
    C:\Program Files\Oracle\JInitiator 1.3.1.22\bin\hotspot
    3) And firefox connection settiong with 'No-Proxy'
    The above setting it will help full you to run your form on firefox.
    Thank you,

  • JFileChooser problem - it will not display

    I have read the tutorial on JFileChoosers and understand the basics, however, my application will simply not display a File Chooser. I select the menu option "open file" and the command prompt window just spews out dozens of garbage. The code is below if there are any FileChooser "Pros" out there. The FileChooser is selected for loading in the actioPerformed method. Thanks for any assistance.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.*;
    public class DissertationInterface extends JFrame implements ActionListener
         private JPanel onePanel, twoPanel, bottomPanel;
           private JButton quit,search;
           private JMenuBar TheMenu;
           private JMenu menu1, submenu;
         private JMenuItem menuItem1;
         private JFileChooser fc;          //FILE CHOOSER
           private BorderLayout layout;
           //Canvas that images should be drew on
           //drawTheImages Dti;
           //Instances of other classes
         //DatabaseComms2 db2 = new DatabaseComms2();
         //Configuration cF = new Configuration();
           public DissertationInterface()
                setTitle("Find My Pics - University Application") ;
                layout = new BorderLayout();          
                Container container = getContentPane();
                container.setLayout(layout);
                //Dti = new drawTheImages();
              //container.add(Dti);
                quit = new JButton("Quit");
                search = new JButton("Search");
                TheMenu = new JMenuBar();
                setJMenuBar(TheMenu);
                //FILE CHOOSER
                JFileChooser fc = new JFileChooser();     
                fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                //First menu option = "File";
                menu1 = new JMenu("File");
              TheMenu.add(menu1);
                //Add an option to the Menu Item
                menuItem1 = new JMenuItem("OPEN FILE",KeyEvent.VK_T);
            menuItem1.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_1, ActionEvent.ALT_MASK));
              menu1.add(menuItem1);
              menuItem1.addActionListener(this);          //action listener for Open file option
                //CREATE 3 PANELS
                onePanel = new JPanel();
                onePanel.setBackground(Color.blue);
                onePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 200, 400)) ;
                twoPanel = new JPanel();
                twoPanel.setBackground(Color.red);
                twoPanel.setLayout(new GridLayout(5,2,5,5));
                bottomPanel = new JPanel();
                bottomPanel.setBackground(Color.yellow);
                bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
              //ADD COMPONENTS TO THE PANELS
                //Add the menu bar and it's items to twoPanel
              twoPanel.add(TheMenu, BorderLayout.NORTH);
              twoPanel.setAlignmentY(LEFT_ALIGNMENT);
                bottomPanel.add(quit);
                quit.addActionListener(this);          //action listener for button
                bottomPanel.add(search);
                search.addActionListener(this);          //action listener for button
                //ADD PANELS TO THE WINDOWS
                container.add(onePanel, BorderLayout.CENTER);
                container.add(twoPanel,BorderLayout.NORTH);            
                container.add(bottomPanel, BorderLayout.SOUTH);
                //setSize(350,350);
                setVisible(true);
              }//END OF CONSTRUCTOR
            public void leaveWindow()
                 this.dispose() ;
            public static void main(String args[])
            DissertationInterface DI = new DissertationInterface();
            DI.setVisible(true);
            //Display the window.
            DI.setSize(450, 260);
            DI.setVisible(true);
            DI.pack();
         }//End of main method
         protected void processWindowEvent(WindowEvent e)
                super.processWindowEvent(e);
                if(e.getID()== WindowEvent.WINDOW_CLOSING)
                      System.exit(0);
              }//End of processWindowEvent
    //method to resolve button clicks etc
    public void actionPerformed(ActionEvent e)
              //PROBLEM IS HERE !!!!!!! - why won't the file dialogue box open
              if(e.getActionCommand().equals("OPEN"))
                   int returnVal = fc.showOpenDialog(DissertationInterface.this);
                 else if(e.getActionCommand().equals("Quit"))
                      //closeDialog();
                      System.out.println("User interface exited");
                      System.exit(1);
                      leaveWindow();
              else if(e.getActionCommand().equals("Search"))
                      //pass params to database                                 
                 }//end of else if
    } //end of method ActionPerformed
    }//End of class DissertationInterface

    I have done as stated, code compiles/executes but when I select the open file option on my GUI, the command prompt window freezes and no dialogue box is displayed!!!!

  • JInternalFrame is not displayed properly in jDesktopPane

    I am developing a project in NetBeans 6.5. I've designed a JInternalFrame "newInvoiceIF" which contains JPanel. The JPanel has Free Design as a layout which is by default in NetBeans. The other components like textfields, labels, separator & buttons are placed on JPanel. My problem is that when JFrame is added to JDesktopPane at the runtime it doesn't display complete JPanel. The width of panel seems to be more than displayed internalframe. Right hand side components are not displayed partially I have set size of the internal frame to the size of desktoppane as shown in the code below.
    NewInvoiceIF newInvoiceIF = new NewInvoiceIF();
    newInvoiceIF.setSize(myDesktopPane.getSize());
    newInvoiceIF.show();
    myDesktopPane.add(newInvoiceIF);
    myDesktopManager.activateFrame(newInvoiceIF);
    I've also tried pack() method but it make internal frame larger than desktoppane & then i need to drag internal frame towards left to see right hand side components. Can anybody tell me solution that'll rearrange components within internalframe at runtime so that all components are displayed within desktoppane size limit.

    Agrees with Olek. It may be time to bite the bullet and learn how to use the many layout managers that are available in Swing. The Sun tutorial dose a decent job explaining these, but I think that it puts a little too much emphasis on the GridBagLayout, one of the more difficult layout managers.

  • JpopupMenu not displaying

    hi all,
    why the JPopupMenu is not displaying here?
    is this line not registering mouseListener
    enableEvents(AWTEvent.MOUSE_EVENT_MASK);
    import java.awt.AWTEvent;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JPopupMenu;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    public class DemoPopUp extends JFrame{
        protected JPopupMenu popupMenu = new JPopupMenu();
        protected JMenuItem m_mniInsertRow;
        protected JMenuItem m_mniInsertScrip;
        protected JMenuItem m_mniDeleterRow;
        protected JMenuItem m_mniDeleteExpiredScrip;
        protected JMenuItem m_mniSetAlert;
        JTable tbl = new JTable(100, 8){
            public Object getValueAt(int row, int col) {
                return row+","+col;
        public DemoPopUp(){
            m_mniInsertRow = new JMenuItem("Insert a Row");
            m_mniInsertScrip = new JMenuItem("Insert a Scrip");
            m_mniDeleterRow = new JMenuItem("Delete a Row");
            m_mniDeleteExpiredScrip = new JMenuItem("Delete a Expired Scrip");
            m_mniSetAlert = new JMenuItem("Set Alert");
            popupMenu.add(m_mniInsertRow);
            popupMenu.add(m_mniInsertScrip);
            popupMenu.add(m_mniDeleterRow);
            popupMenu.add(m_mniDeleteExpiredScrip);
            popupMenu.add(m_mniSetAlert);
            enableEvents(AWTEvent.MOUSE_EVENT_MASK);
            JPanel jp = new JPanel();
            JScrollPane src = new JScrollPane(tbl);
            jp.add(src);
            getContentPane().add(jp);
            setVisible(true);
            pack();
            setDefaultCloseOperation(EXIT_ON_CLOSE);
        public void processMouseEvent( MouseEvent evt )
            if( evt.isPopupTrigger() )
              JTable source = (JTable)evt.getSource();
              int row = source.rowAtPoint( evt.getPoint() );
              int column = source.columnAtPoint( evt.getPoint() );
              System.out.println(column);
              source.changeSelection(row, column, false, false);
              popupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
        public static void main(String[] args)
            new DemoPopUp();
    }thanks
    daya

    is this line not registering mouseListener
    enableEvents(AWTEvent.MOUSE_EVENT_MASK);No and you don't need that line.
    For general usage of a MouseListener, read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/events/handling.html]How to Use a Mouse Listener
    For specific information on popups, read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#popup]Bringing Up a Popup Menu for a working example.

  • Error raised using 'CRM_MESSAGE_COLLECT' not displayed in Web UI

    Hello,
    I have implemented the badi CRM_ORDERADM_H_BADI and based on certain conditions i raise an exception and display the error message using function module 'CRM_MESSAGE_COLLECT'. The application log is populated with the error message and I am able to see the error message in SAP GUI . However when the same transaction is triggered via WebUI , even thought the exception is raised , the error message is not displayed.
    I know i can use the method ADD_MESSAGE of the class CL_CRM_GENIL_GLOBAL_MESS_CONT if i want the error message to be displayed in Web UI .
    However I want the message to be displayed either if the transaction is run from the SAP GUI or web UI .
    Have anyone come across the similar situation , is there something I am missing.
    Thanks & Regards ,
    Sriram.

    Hello Arun ,
         I got the solution . The error message was raised properly . The problem is  message filter at every view or viewset of a component is actually switched off by default.With standard components the filter gets activated at runtime if the component controller contains a BOL entity.
    In our case , since it was a custom component with no BOL entity the filter was switched off and hence the messages from the application level were not read.
    Therefore we redefined the filter method IF_BSP_WD_STATE_CONTEXT~GET_MESSAGE_FILTER at the view/viewset level and turned on the filter by default.hence even if the component does not return an entity the message filter gets activated.
    Thanks for your inputs.
    Thanks & Regards,
    Sriram

Maybe you are looking for