This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Pages: 1 - Last Post: 8 Dec 20, 20:39 Last Post By: AndreWolff
AndreWolff

Posts: 1,289
Registered: 14-Dec-2007
Double JLabelFor text in custom panel
Posted: 3 Dec 20, 19:00
 
  Click to reply to this thread Reply
I did extend the compiled FancyBox custom panel with a new field for an URL preceded by a JLabelFor text which looks for the first image as displayed in the attached screenshot CustomPanelImage1.png
But is I select the next image I see the JLabelFor text twice as shown in the attached screenshot CustomPanelImage2.png
A next image shows 3 JLabelFor text etc.

What should be corrected in the next code (src file also enclosed)?
class FancyBoxCustomUI extends JCustomPanel {
 
    AlbumObject cAO;
    AlbumObjectProperties cProps;
    JCheckBox panoramicSphericalImage = new JCheckBox("Spherical panoramic image", false);
    JCheckBox panoramicImage = new JCheckBox("Cylindrical panoramic image", false);
    JCheckBox pan360 = new JCheckBox("<html>360° panorama</html>", false);
    JSmartTextField moreInfoURL = new JSmartTextField();
 
    public void setAlbumObject(AlbumObject ao) {
        super.setAlbumObject(ao);
        removeAll();
        if (ao != null) {
            cAO = ao;
            cProps = cAO.getProperties();
            File currentContextFile = ao.getFile();
            boolean isFolder = cAO.getCategory() == Category.folder;
            boolean isImage = cAO.getCategory() == Category.image;
            if (isFolder) {
                add(new JLabelFor("URL for 'More info' button:", moreInfoURL));
                add("br hfill", moreInfoURL);
                moreInfoURL.setEnabled(isFolder);
            } else if (isImage)  {
                add("br", panoramicSphericalImage);
                add("br", panoramicImage);
                add("br", pan360);
                panoramicSphericalImage.setEnabled(isImage);
                panoramicImage.setEnabled(isImage);
                pan360.setEnabled(isImage);
                pan360.setEnabled(panoramicImage.isSelected());
            } else {
                // close and remove the custom panel, how should I do that?
                return;
            }
            loadUI();
        }
    }
 
    public FancyBoxCustomUI(JAlbumContext context) {
        super(context);
        // Set up the UI
        setBackground(SystemColor.text);
        setOpaque(true);
        panoramicSphericalImage.setBackground(SystemColor.text);
        panoramicImage.setBackground(SystemColor.text);
        pan360.setBackground(SystemColor.text);
 
        pan360.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                cProps.save();
            }
        }
        );
 
        panoramicSphericalImage.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (panoramicSphericalImage.isSelected()) {
                    panoramicImage.setSelected(false);
                    pan360.setEnabled(false);
                    cProps.remove("maxImageWidth");
                    cProps.remove("panoramicImage");
                    cProps.remove("pan360");
                }
                cProps.save();
            }
        }
        );
 
        // Enable maxImageWidth field if panoramicImage is checked, otherwise remove userVariables
        panoramicImage.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (panoramicImage.isSelected()) {
                    panoramicSphericalImage.setSelected(false);
                    cProps.put("maxImageWidth", "50000");
                } else {
                    cProps.remove("maxImageWidth");
                    cProps.remove("panoramicImage");
                    cProps.remove("pan360");
                }
                cProps.save();
                pan360.setEnabled(panoramicImage.isSelected());
            }
        }
        );
        init();
    }
}


Edit: File FancyBoxCustomUi.java enclosed

Edited by: AndreWolff on 03-Dec-2020 19:03

Edit: code updated,

Edited by: AndreWolff on 06-Dec-2020 11:46
AndreWolff

Posts: 1,289
Registered: 14-Dec-2007
Re: Double JLabelFor text in custom panel
Posted: 4 Dec 20, 10:05   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Adding a removeAll did solve the problem:
  public void setAlbumObject(AlbumObject ao) {
    super.setAlbumObject(ao);
    removeAll();
I am still not sure whether I have to add saveUI(); as well
ctwist

Posts: 471
Registered: 27-Sep-2003
Re: Double JLabelFor text in custom panel
Posted: 4 Dec 20, 15:21   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
I don't call saveUI() in CustomUI.

I suggest you should remove it.

Edited by: ctwist on 04-Dec-2020 09:44

However David's example http://jalbum.net/help/en/Creating_a_custom_user_interface does call saveUI(). Maybe my technique is not up to date. You should replicate David's first example, but you should call saveUI() in an ActionListener.
davidekholm

Posts: 3,440
Registered: 18-Oct-2002
Re: Double JLabelFor text in custom panel
Posted: 8 Dec 20, 20:23   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
saveUI() is called whenever jAlbum calls setAlbumObject() to switch between images, but you can naturally call it more often too. Here's the source code for JCustomPanel for your reference/understanding
AndreWolff

Posts: 1,289
Registered: 14-Dec-2007
Re: Double JLabelFor text in custom panel
Posted: 8 Dec 20, 20:39   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Here's the source code for JCustomPanel for your reference/understanding
That does not help me a lot, I would prefer if you said what is wrong with the code showed above and which works correct without calling SaveUi().
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums