Search code examples
javajpanelwidgetmacoshud

How to add a widget from the mac_widgets java api to HudWindow


Good day,

I recently came accross the mac_widgets api for java. I went through the docementation and exaples but i didn't find a way to add widgets to the HudWindow. I came accross an online solution

panel.setLayout(new BoxLayout?(panel, BoxLayout?.Y_AXIS)); panel.add(sourceList.getComponent());

This works if panel is a reference to a JPanel object and it is add to a JFrame window.

Is there a way i can add panel to the HudWindow in the mac_widgets api?


Solution

  • Try the following code, of course you wont get the transparency. But this is how you add a panel to a HUD window. Try extracting the MacWiget.jar file to view other classes. The components have different names, in this case a panel is called ActivePanel.

    import javax.swing.JButton;
    
    import com.explodingpixels.macwidgets.ActivePanel;
    import com.explodingpixels.macwidgets.HudWidgetFactory;
    import com.explodingpixels.macwidgets.HudWindow;
    
    public class MacWidgetTest {
    
    
        public static void main(String[] args) {
            setGUI();   
        }
    
        public static void setGUI() {
            System.out.println("Starting GUI");
            HudWindow hud = new HudWindow("Window");
            hud.getJDialog().setSize(300, 350);
            hud.getJDialog().setLocationRelativeTo(null);
            ActivePanel panel = new ActivePanel();
            JButton button = HudWidgetFactory.createHudButton("Button");
            panel.add(button);
            hud.setContentPane(panel);
            hud.getJDialog().setVisible(true);
        }
    
    }