0

Hello!

I have the problem with my program visualization at different computers (but the same OS). Below you may see some code pieces related to creating the user interface. Everything is ok with this code at my computer. But I cannot understand why it produces different layouts at some other computers. For example, the top menu (JPanel->pantop) is displayed in a wrong way, i.e. the top menu (toolBarMenu) is out of the borders of the JPanel->pantop.

An one more very strange aspect is that when I open my program by double-clicking - all icons (for buttons) are displayed correctly. But if I run the program through Open with (and then select Java Platform SE binary), the icons are not displayed.

Please, help me to improve the code and fix the error. Thank you!

public Form() throws IOException
    {
        designForm();
       
        createTopMenu();
...
        this.setVisible(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);
        this.pack();

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
                // Exit the application
                tableModel.closeDB();
                System.exit(0);
            }
        });
    }


    private void designForm() {
        Image icon = Toolkit.getDefaultToolkit().getImage("src/icons/system_icon.png");
        this.setIconImage(icon);

        toolkit = Toolkit.getDefaultToolkit();
	screenDim = toolkit.getScreenSize();
        int deltax = (int) (0.05 * screenDim.width); int deltay = (int) (0.1 * screenDim.height);
        this.setSize(screenDim.width-deltax,screenDim.height-deltay);

        bord = new DropShadowBorder(Color.BLACK, 7);

        pan = new JPanel(new BorderLayout());
        pan.setVisible(true);
        pan.setOpaque(true);

        fontButtons = new Font("Arial", Font.BOLD, 14);
        colorSelectedButtons = new Color(79,148,205);
        colorUnselectedButtons = new Color(108,123,139);

        pantop = new JPanel(new MigLayout("wrap","grow, fill"));
        deltax = this.getWidth(); deltay = (int) (0.15 * this.getHeight());
        pantop.setPreferredSize(new Dimension(deltax, deltay));

        panfortree = new JPanel(new MigLayout());
        panfortree.setBorder(bord);
        deltax = (int) (0.25 * this.getWidth()); deltay = (int) (0.85 * this.getHeight());
        panfortree.setPreferredSize(new Dimension(deltax, deltay));

        panfortab = new JPanel(new MigLayout("fill"));
        panfortab.setBorder(bord);
        deltax = (int) (0.75 * this.getWidth()); deltay = (int) (0.85 * this.getHeight());
        panfortab.setPreferredSize(new Dimension(deltax, deltay));

        pan.add(pantop, BorderLayout.PAGE_START);
        pan.add(panfortab,  BorderLayout.CENTER);
        pan.add(panfortree, BorderLayout.LINE_START);

        add(pan);

    }

    private void createTopMenu() {
        JPanel userpanel = new JPanel();
        JLabel username = new JLabel(this.login);
        username.setFont(new Font("Arial", Font.BOLD, 12));
        username.setForeground(new Color(79,148,205));
        JLabel usericon = new JLabel(new ImageIcon("src/icons/user.png"));
        userpanel.add(username); userpanel.add(usericon);
        pantop.add(userpanel, "gapleft push, wrap");

        JPanel clockpanel = new JPanel();
        Clock clock = new Clock();
        JLabel clockicon = new JLabel(new ImageIcon("src/icons/clock.png"));
        clockpanel.add(clock); clockpanel.add(clockicon);
        pantop.add(clockpanel, "gapleft push, wrap");

        String[] toolbarLabels = { "Home", "Messages", "Help"};
        toolBarMenu = new BrowserToolBar(toolbarLabels);
        toolBarMenu.setOrientation(0);
        toolBarMenu.setBorderPainted(false);
        toolBarMenu.setOpaque(false);
        toolBarMenu.setFloatable(false);
        pantop.add(toolBarMenu);

        for (int i=0; i<toolBarMenu.getComponentCount(); i++) {
          final int jIndex = i + 1;
          toolBarMenu.getButton(i).setBorderPainted(false);
          toolBarMenu.getButton(i).addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createBase(jIndex);
            }
          });
        }
    }

Edited by LianaN: n/a

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by LianaN
0

Well, I've solved the problem with icons - just embedded them into JAR file. But why the top menu sometimes is out of the border of the JPanel->pantop (the text is partly invisible)?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.