Panel.setPreferredSize() doesn't work

I have a internal frame. In this internal frame, I need to dynamic generate panels and put labels data in each panel.
The panels and labels are generate correctly, but panel.setPreferredSize() doesn't work.
I hope each panel can have the same width. can someone take a look for me? Thanks a lot~~
Here is my code. When the internal frame is initialized, it will call addPanel() function.
public void addPanel(int[][] cluster, String[] labels, String[][] searchResult){
         JPanel mainPanel = new JPanel();
         mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
        mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
         //panel for clusters
         JPanel[] clusterPanel = new JPanel[cluster.length];
         docsLabel = new JLabel[searchResult[3].length];
         int docIndex, docsLabelIndex=0;
         for(int i=0;i<cluster.length;i++){
              //set up border for cluster panel
              clusterPanel=new JPanel();
               clusterPanel[i].setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(labels[i]),
BorderFactory.createEmptyBorder(3,3,3,3)));
               clusterPanel[i].setLayout(new BoxLayout(clusterPanel[i],BoxLayout.Y_AXIS));
          for(int j=0;j<cluster[i].length;j++){
               docIndex=cluster[i][j];
               labelsIndex[docIndex]=docsLabelIndex;
               docsLabel[docsLabelIndex]= new JLabel(url[docIndex]);
               docsLabel[docsLabelIndex].setToolTipText(searchResult[3][docIndex]);
               docsLabel[docsLabelIndex].setHorizontalTextPosition(JLabel.LEFT);
               docsLabel[docsLabelIndex].setOpaque(true);
               docsLabel[docsLabelIndex].addMouseListener(this);
               clusterPanel[i].add(docsLabel[docsLabelIndex]);
               clusterPanel[i].addMouseListener(this);
               clusterPanel[i].setName(Integer.toString(i));
               docsLabelIndex++;
               clusterPanel[i].setPreferredSize(new Dimension(200, 50)); ----------------->this doesn't work
          clusterPanel[i].setOpaque(true);
               mainPanel.setOpaque(true);
               mainPanel.add(clusterPanel[i]);
     ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
          sp.setBounds(2,2,2,2);
          sp.setVisible(true);
          sp.add(mainPanel);
     this.add(sp);

are you sure that the panels are the ones that are the wrong size? Maybe the contents of the panels sizes only make it look that way. Try setting different types of components to have different background colors to see what's what.
Keep in mind that preferred size only specifies the preferred size. It doesn't mean that a layout manager has to respect that. Although, I would expect BoxLayout to do so.

Similar Messages

  • ICloud Control panel absolutely doesn't work

    So I downloaded iCloud Control Panel on my PC with Windows 7 Ultimate x64 and it doesn't work. It doesn't recognize that I have Microsoft Outlook, even though it's Outlook 2007, It doesn't merge the bookmarks and I can't activate Photo stream because this option on iCloud Control Panel is all grayed out. Here is a screenshot: http://img64.imageshack.us/img64/3097/icloude.png
    So what can be blocking iCloud Control Panel? I don't use any antivirus software, so that's not a problem. I also tried to use the iCloud control panel in my sisters notebook and it works perfectly.

    V1597psh wrote:
    The problem was solved by myself.
    Thanks

  • Tabbed Panels: Opening panel with panel number doesn't work with Spry Data

    I have some data inside a TabbedPanelsContent div, and would
    like to be able to open tabs using links, but it only seems to work
    with static content.
    Clicking on tabs themselves loads content correctly, whereas
    clicking on links does nothing. I tried both - panel number and
    panel ID - neither worked. What gives?
    See code below.
    <div spry:region="ds1">
    <div class="TabbedPanels" id="tp1">
    <ul class="TabbedPanelsTabGroup">
    <li class="TabbedPanelsTab" tabindex="0">Asset
    Management</li>
    <li class="TabbedPanelsTab"
    tabindex="0">Brokerage</li>
    <li class="TabbedPanelsTab" tabindex="0">Mutual
    Funds</li>
    </ul>
    <div class="TabbedPanelsContentGroup">
    <div class="TabbedPanelsContent">
    <p spry:repeat="ds1"
    spry:test="'{@industry01}'.search(/^Asset Management/) !=
    -1;">{ds1::client}</p>
    </div>
    <div class="TabbedPanelsContent">
    <p spry:repeat="ds1"
    spry:test="'{@industry02}'.search(/^Brokerage/) !=
    -1;">{ds1::client}</p>
    </div>
    <div class="TabbedPanelsContent">
    <p spry:repeat="ds1"
    spry:test="'{@industry03}'.search(/^Mutual Funds/) !=
    -1;">{ds1::client}</p>
    </div>
    </div>
    </div>
    <script type="text/javascript">
    var tp1 = new Spry.Widget.TabbedPanels("tp1");
    </script>
    </div>
    <a href="#" onclick="tp1.showPanel(0); return
    false;">Asset Management</a>
    <a href="#" onclick="tp1.showPanel(1); return
    false;">Brokerage</a>
    <a href="#" onclick="tp1.showPanel(2); return
    false;">Mutual Funds</a>

    Try to declare the variable out side of the region
    <script> var tp1;</script>
    <div spry region ... >
    tab panel stuff
    <script type="text/javascript">
    tp1 = new Spry.Widget.TabbedPanels("tp1");
    </script>
    </div>

  • 3 Questions: Docking Panels, Find doesn't work

    Hello, I am relatively new to Prelude and I have three questions.
    -First for some reason I no longer can move the panels to other positions and lock them in. That little hot spot tab is missing ??
    -Secondly, The finder in the project panels isn't finding anything I enter (names of clips, subclass, comments. What am I doing wrong?
    -Thirdly the Marker Type panel used to show five types of markers and now is only showing three (Subclip, Comment, and Speech Transcription.).
    I have tried resetting the workspace, close and reopen the application and even reboot my computer.. Nothing helps.
    I am currently using the latest version .. Prelude cc 2014.
    I am on a mid 2010 iMac with OS X Yesomite..
    Thanks
    Ken

    Hi Ken,
    now108 wrote:
    Hello, I am relatively new to Prelude and I have three questions.
    -First for some reason I no longer can move the panels to other positions and lock them in. That little hot spot tab is missing ??
    It works the same way. Just drag the main tab to a new location. You'll see the familiar "purple shapes."
    now108 wrote:
    -Secondly, The finder in the project panels isn't finding anything I enter (names of clips, subclass, comments. What am I doing wrong?
    Not sure. Seems to work OK for me. Try ingestion different media from another folder.
    now108 wrote:
    -Thirdly the Marker Type panel used to show five types of markers and now is only showing three (Subclip, Comment, and Speech Transcription.).
    There were some pretty big changes there all related to custom tagging. See these resources:
    Prelude Help | New features summary
    Adobe Prelude CC 2014 Update | AdobePrelude
    Hope that helps.
    Thanks,
    Kevin

  • Bug or feature? Panel layout doesn't work when Stage contained in class

    I have found a very strange behavior. But can't really understand what goes wrong. So I hope I can get some hints here.
    Just try the following demo:
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.layout.Panel;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    import javafx.scene.layout.Container;
    public function run(   ) {
      //Remove the next two lines for a miracle!
      Asdf {}}
    public class Asdf {
      def stage: Stage = Stage {
          scene: Scene {
            width: 800
            height: 600
            content: [
                def p: Panel = Panel {
                    width: bind stage.scene.width
                    height: bind stage.scene.height
                    onLayout: function (): Void {
                      p.resizeContent();
                      for ( node in Container.getManaged( p.content ) ) {
                        Container.positionNode( node, indexof node * 20 + 50, indexof node * 30 + 40, true );
                    content: [
                      Rectangle {
                        width: 140, height: 90
                        fill: Color.ORANGE
                        opacity: 0.5
                      Rectangle {
                        width: 100, height: 120
                        fill: Color.BLUE
                        opacity: 0.5
    }The layout function is called, but the values are not respected...
    Now just remove the two lines containing the object initialization and class definition. It should look like that:
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.layout.Panel;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    import javafx.scene.layout.Container;
    public function run(   ) {
      //Remove the next two lines for a miracle!
    //  Asdf {}}
    //public class Asdf {
      def stage: Stage = Stage {
          scene: Scene {
            width: 800
            height: 600
            content: [
                def p: Panel = Panel {
                    width: bind stage.scene.width
                    height: bind stage.scene.height
                    onLayout: function (): Void {
                      p.resizeContent();
                      for ( node in Container.getManaged( p.content ) ) {
                        Container.positionNode( node, indexof node * 20 + 50, indexof node * 30 + 40, true );
                    content: [
                      Rectangle {
                        width: 140, height: 90
                        fill: Color.ORANGE
                        opacity: 0.5
                      Rectangle {
                        width: 100, height: 120
                        fill: Color.BLUE
                        opacity: 0.5
    }Now everything works as expected... Any hints? What did I miss?

    I have found a very strange behavior. But can't really understand what goes wrong. So I hope I can get some hints here.
    Just try the following demo:
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.layout.Panel;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    import javafx.scene.layout.Container;
    public function run(   ) {
      //Remove the next two lines for a miracle!
      Asdf {}}
    public class Asdf {
      def stage: Stage = Stage {
          scene: Scene {
            width: 800
            height: 600
            content: [
                def p: Panel = Panel {
                    width: bind stage.scene.width
                    height: bind stage.scene.height
                    onLayout: function (): Void {
                      p.resizeContent();
                      for ( node in Container.getManaged( p.content ) ) {
                        Container.positionNode( node, indexof node * 20 + 50, indexof node * 30 + 40, true );
                    content: [
                      Rectangle {
                        width: 140, height: 90
                        fill: Color.ORANGE
                        opacity: 0.5
                      Rectangle {
                        width: 100, height: 120
                        fill: Color.BLUE
                        opacity: 0.5
    }The layout function is called, but the values are not respected...
    Now just remove the two lines containing the object initialization and class definition. It should look like that:
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.layout.Panel;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    import javafx.scene.layout.Container;
    public function run(   ) {
      //Remove the next two lines for a miracle!
    //  Asdf {}}
    //public class Asdf {
      def stage: Stage = Stage {
          scene: Scene {
            width: 800
            height: 600
            content: [
                def p: Panel = Panel {
                    width: bind stage.scene.width
                    height: bind stage.scene.height
                    onLayout: function (): Void {
                      p.resizeContent();
                      for ( node in Container.getManaged( p.content ) ) {
                        Container.positionNode( node, indexof node * 20 + 50, indexof node * 30 + 40, true );
                    content: [
                      Rectangle {
                        width: 140, height: 90
                        fill: Color.ORANGE
                        opacity: 0.5
                      Rectangle {
                        width: 100, height: 120
                        fill: Color.BLUE
                        opacity: 0.5
    }Now everything works as expected... Any hints? What did I miss?

  • "Show Panels" (F4) doesn't work

    I already uninstalled and reinstalled Dreamweaver CS6.  Didn't help.  Followed the instructions here related to deleting the cache.  Didn't work.
    Please help!  I really need to be able to toggle those panels to have more screen real estate.  It's driving me nuts that this suddenly stopped working.

    I was having some other problems that I posted in a separate discussion.  That user suggested I try following the instructions at http://www.dmxzone.com/go/16740/clearing-dreamweaver-s-cache/.  I did, and that seems to have fixed this issue as well.  Thanks all for the input, even though it didn't help.

  • Mouse clicks, scrolling doesn't work in applications from start screen (let's call it "tile application")

    Hello!
    I need help.
    2 days ago the mouse worked fine. Yesterday I noticed that the mouse scroll does not work in the "Book Bazaar Reader". Now I found that the right mouse button and left mouse button does not work in some applications, but scrolling work in these applications.
    In mail application clicks work in some panels, scrolling doesn't work.
    In desktop mode, the mouse works perfectly.
    Please help!

    Hi
    Since at desktop mode everything fine, i suspected some application or 3rd party SW change your mouse setting
    Go to run, msconfig, run as administrator, within the System Configuration dialogue box find startup tab, find KHALMNPR (if you using logitec mouse) and uncheck it
    click ok and restart
    or try to do clean boot to eliminate 3rd party SW issue

  • Woke computer from Sleep: USB doesn't work

    So, I woke my computer from sleep, and now all my USB ports are dead.
    I tried restarting, resetting the CMOS, removing the D-Bracket, which I had just installed (it didn't work either.).  Any thoughts?
    EDIT:  All ports get power, none get signal.

    Quote
    Originally posted by etruscan
    This appears to be a partial fix.  Now the USB root hubs work (i.e. the expansion bits, so I have a D-Bracket and the front Panel USB working.  However, the Back panel still doesn't work, as it appears to be controlled by the "Standard Enhanced PCI to USB Host Controller and the "Standard OpenHCD USB Host Controller," neither of which have power management.
    Any further suggestions are appreciated.
    Okay, with your front panel connectors, do they have a wire for pin 10 on the USB connector?  That would be the one next to the blocked out keying pin (pin 9).  If so, that could be causing your problem.  If you remove the pin from the connector that could clear up the problem.  I haven't personally had the issue, but I've seen it talked about.  If your internal USB connectors only have 8 wires on them, then I don't know what to tell you...

  • Firefox always opens with the last page from previous session. Setting this right (e.g. changing this to start up with blank or startup page) in Options/General, doesn't work.

    Screenshot of the options panel (that doesn't work):
    http://img170.imagevenue.com/img.php?image=214144211_FF_122_209lo.jpg

    All these "solutions" that have been offered to go to your settings and set your option to go to home page are 1.) not working and 2.) kind of a"duh". How many of us do you think have been set up like that for a few years now? And yet all of a sudden (i.e. new version of Firefox that apparently needs a little more testing...), this problem is occurring. It's getting really annoying too. We have defined home pages for a reason. Please correct this so we can return to them when we log in.

  • Option System recovery doesn't work

    Notebook Lenovo G50-30 (80G0) - bought a month ago. (Windows 8.1)
    Few days ago sound stopped work suddenly. I suspect that this is associated with MS Updates, which was set as automatic. I suspect because this notebook is not my. But now I have it for repair. I noticed that system work abnormally, when I try to use some function from control panel it doesn't work and control panel stop responding. For example update settings. 
    I decided restore system to factory setting, using NOVO key and option System Recovery. Unfortunately when I choose this option nothing happens and computer loading operating system as usually. I try use software OneKeyRecovery and after it sytuation is the same. 
    Important information is that system partition C was divided into two parts/partitions. And it was my first clue that something is wrong with ID partitions, but maybe i'm wrong. I change it and set one C volume.
    Diskpart shows 5 volumes (0-4), the last one is the recovery partition like below:
    On computer: LENOVO-G50
    Volume ### Ltr Label Fs Type Size Status Info
    Volume 0 E DVD-ROM 0 B No Media
    Volume 1 C Windows8_OS NTFS Partition 450 GB Healthy Boot
    Volume 2 WINRE_DRV NTFS Partition 1000 MB Healthy Hidden
    Volume 3 SYSTEM_DRV FAT32 Partition 260 MB Healthy System
    Volume 4 PBR_DRV NTFS Partition 13 GB Healthy Hidden
    Partition 5
    Type : de94bba4-06d1-4d40-a16a-bfd50179d6ac
    Hidden : Yes
    Required: Yes
    Attrib : 0X8000000000000001
    Offset in Bytes: 486004490240
    Volume ### Ltr Label Fs Type Size Status Info
    * Volume 4 PBR_DRV NTFS Partition 13 GB Healthy Hidden
    Can someone help me? How can I restore factory settings?

    hi mehowg,
    Can you try to create a recovery drive and use it to Refresh or Reset Windows 8/8.1.
    If that doesn't work, you can try the folliwing to reinstall the OS:
    1. Check this guide on how to obtain a Windows 8.1 ISO (see Option One)
    2. After you set Boot Mode to UEFI in the BIOS, follow this guide to make a bootable UEFI Win8.1 installer via DVD/USB flashdrive and use it to install Windows 8.1 on the G50-30 (the installation should be able to detect the Windows 8.1 product key in the UEFI firmware that will let you activate Windows).
    Note:
    The above method (Steps 1-2) will only re-install Windows (you will need to reinstal the drivers manually from the G50-30 drivers page)
    Let me know how it goes.
    Regards
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"! This will help the rest of the Community with similar issues identify the verified solution and benefit from it.
    Follow @LenovoForums on Twitter!

  • [Photoshop CC 2014] Click&hold-move-release doesn't work when adding adjustment layer from the layer panel

    When selecting a menu item I used to click the left mouse button and hold it down, move the pointer to the desired menu item and release the mouse button. Everything works fine in the mine menu, but there's a problem when adding new adjustment layer from the layer panel: when I release the button nothing happens, I have to press the button again. In previous PS version it worked fine. How can I fix this?

    I don't think that is user fixable, meaning you'll have to wait till adobe fixes it with an update.
    Photoshop cc 2014
    windows does not work
    mac does work
    Did you already post over here:
    [Photoshop CC 2014] Click&hold-move-release doesn't work when adding adjustment layer from the layer panel

  • I just reinstalled PSE 9 and now my edit effects panel doesn't work when I click on it. Help!

    If anybody had this problem and has the solution, please share and I'll be a happy camper again. I have Window Vista. Thanks.

    Hi,
    When you are saying that the edit effect panel doesn't work, Do you mean there is nothing in the panel (It is an empty panel) or there are items but when clicked nothing is happening ?
    Also, Is it the case with Edit Effect panel only or other panels are also behaving in same way ?

  • Qosmio F50-10z' s front operation panel doesn't work

    My front operation panel doesn't work. I have tried to recovery my computer and reinstall the VAP but it still doesnt work.
    I want to why...

    Hi!
    What do you mean with if it doesnt work?
    If you try to install a newer version of Toshiba Value Added Package you should remove the old version first. Reboot the notebook and install the newer one.
    Last but not least try to update the BIOS. You can find it on the Toshiba website:
    http://eu.computers.toshiba-europe.com => Support & Downloads => Download Drivers
    Bye

  • MEGA 180 front panel's MIC socket doesn't work

    but the MIC socket behind works fine?
    so which part could be the problem? the mainboard?or the front MIC socket itself?

    Quote from: Dr Stu on 26-August-05, 00:59:20
    does the front headphone socket work? open the mega case and check the connections from the front panel to the mainboard
    the front headphone socket works fine
    Quote from: otrofox on 26-August-05, 05:25:46
    Are you sure that it doesn't work? That line is called "microphone2" and must be activated separately.
    what do you mean "activated separately"? is that means that i can't use the front MIC socket when the behind one is plugged?

  • ActionPerformed doesn't work

    Hi all,
    I have a JInternalFrame with two JPanel (firstPan and secondPan). In firstPan I put a JTree.
    When the user click on a node of JTree I views a specific JPanel into secondoPan.
    This JPanel is different for every node of JTree
    I have a class for every specific JPanel (extends JPanel)
    This is the code that do this:
    if (secondPan.getComponents().length > 0) {
    secondPan.remove(secondPan.getComponent(0));
    JPanel pan = new PianSpedUdsPan(this, treeNode, treeObj);
    secondPan.add(pan, BorderLayout.CENTER);
    secondPanPan.paintAll(dettaglioTreePan.getGraphics());
    secondPan.validate();
    This works fine!
    The secondPan views the new JPanel correctly!
    In PianSpedUdsPan (the new JPanel) I have a JButton.
    I add an ActionListener to this button, but when the user click on it
    no events called!
    The MouseClicked works fine.
    The button have a toolTipTex, also this doesn't work! Nothing tooltip appears!
    Someone help me? I don't know where is the problem. I tried a lot of solutions but all don't work
    Thanks
    Monica

    This is the correct line:
    secondPan.paintAll(secondPan.getGraphics());Normally there is no need for calling getGraphics.
    A call of secondPan.revalidate() should be enough.
    At most you could include a secondPan.repaint() also.
    Anyway, this seems to work fine:
    * TreePanelsDemo.java
    package tree;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    public class TreePanelsDemo extends JFrame {
        private JTree tree;
        private JPanel secondPan;
        public TreePanelsDemo() {
            super("Tree Panels Demo");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setSize(400,300);
            setLocationRelativeTo(null);
            tree = new JTree();
            secondPan = new JPanel();
            tree.addTreeSelectionListener(new TreeSelectionListener() {
                public void valueChanged(TreeSelectionEvent evt) {
                    jTree1ValueChanged(evt);
            getContentPane().add(new JScrollPane(tree), BorderLayout.WEST);
            secondPan.setLayout(new BorderLayout());
            getContentPane().add(secondPan, BorderLayout.CENTER);
        private void jTree1ValueChanged(TreeSelectionEvent evt) {
            Object treeNode = tree.getLastSelectedPathComponent();
            if (secondPan.getComponents().length > 0) {
                secondPan.remove(secondPan.getComponent(0));
            String treeObj = treeNode.toString();
            JPanel pan = new PianSpedUdsPan(this, treeNode, treeObj);
            secondPan.add(pan, BorderLayout.CENTER);
            secondPan.revalidate();
        public static void main(final String args[]) {new TreePanelsDemo().setVisible(true);}
    class PianSpedUdsPan extends JPanel{
        private JToolBar jToolBar1;
        public PianSpedUdsPan(JFrame parent, Object node, String str){
            add(new JLabel(str));
            jToolBar1 = new JToolBar();
            JButton deselezionaBut = new JButton();
    //        deselezionaBut.setIcon(new ImageIcon(getClass().getResource("/it/infolog/sce/resources/ivolume_togli.png")));
            deselezionaBut.setToolTipText("Escludi dalla spedizione");
            deselezionaBut.setMaximumSize(new Dimension(40, 40));
            deselezionaBut.setMinimumSize(new Dimension(40, 40));
            deselezionaBut.setPreferredSize(new Dimension(40, 40));
            deselezionaBut.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    deselezionaButActionPerformed(evt);
            jToolBar1.add(deselezionaBut);
            add(jToolBar1);
        private void deselezionaButActionPerformed(ActionEvent evt) {
            System.out.println("---- actionPerformed -----");
    }

Maybe you are looking for

  • Help on Help - is there any way to code "\n" on help information

    I'd like to be able to format the help information by adding newlines as well as forcing it to appear at a certain column I'd like to put a "\n" in my help; is there any way to do so? I also notice that when you have multiple dictionaries in 1 AFC, t

  • X48 platinum LGA 775 mboard will only post in safe mode

    I recently had a problem with my power supply (helped out by members of this forum) and have since changed it. Then the stock cpu cooler seemed to be playing up as the system would only post every tenth (or so) attempt. I therefore went out and purch

  • Accounts Payable Line Item Extraction to BW from SAP using Business Content

    Hi, I have to set up the AP Line Item extraction into BW using the Standard Business Content. Could someone please gide me through the process for doing it ( Step-by-Step if possible), both from the SAP R/3 side and the BW side. Any help deeply appre

  • Record not shown in table control

    Hi experts, I am working on the module pool program with a screen 0100. There is a table control called TABL_MATR in screen 0100. There is no error while compiling the program. But no record shown when a record added into the table control. I do not

  • Attachments in Outlook Integration

    Hello experts, I have troubles enclosing attachments using Outlook Integration. A customer wants to add more attachments to a mail, for example a Purchase Order (PDF) and a logo (PNG, GIF etc.). When a new purchase order is saved and I click the mail