Link to home
Start Free TrialLog in
Avatar of gbcbr
gbcbrFlag for Cyprus

asked on

Panel layout

Please advise how to create layout for jPanel like this: jPanel.tiff
this I create directly into jFrame and I can set exact position for each component manually in JDeveloper.
For jPanel I have headache 10 hours, I tried different layouts, but anyway I don't wished result.
public class DCC extends JFrame {
    private JMenuBar menuBar = new JMenuBar();
    private JMenu menuFile = new JMenu();
    private JMenuItem menuFileExit = new JMenuItem();
    private JPanel jPanel1 = new JPanel();
    private JLabel jLabel1 = new JLabel();
    private PaneLayout paneLayout1 = new PaneLayout();
    transient IGateway mFxcmGateway;
    private JToggleButton jToggleButton1 = new JToggleButton();

    private static DecisionCenter_EURUSD_S dc_EURUSD_S;
   
    private PaneLayout paneLayout2 = new PaneLayout();


    public DCC() {
        try {
            jbInit();
            this.mFxcmGateway = DBFXConnect.getGateway();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        
        this.setJMenuBar(menuBar);
        this.getContentPane().setLayout(null);
        this.setSize(new Dimension(1326, 596));
        this.setTitle("DCC 60");
        this.setAlwaysOnTop(true);
        this.setLocation(500, 100);
        this.setVisible(true);

        this.getContentPane().add(jPanel1, null);
        
        menuFile.setText("File");
        menuFile.add(menuFileExit);

        menuFileExit.setText("Exit");
        menuFileExit.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    fileExit_ActionPerformed(ae);
                }
            });

        menuBar.add(menuFile);

        jPanel1.setBounds(new Rectangle(15, 10, 1270, 30));
        jPanel1.setSize(new Dimension(1270, 30));
        jPanel1.setPreferredSize(new Dimension(1270, 30));
        jPanel1.setMinimumSize(new Dimension(1270, 30));

        


        jPanel1.setMaximumSize(new Dimension(1270, 30));
        jPanel1.setLayout(paneLayout1);
        jLabel1.setText("EUR/USD");
        jLabel1.setSize(new Dimension(80, 30));
        jLabel1.setFont(new Font("Lucida Grande", 1, 14));
        jLabel1.setForeground(Color.blue);
        jLabel1.setLayout(null);

        jToggleButton1.setText("SELL");
        jToggleButton1.setBounds(new Rectangle(190, 40, 120, 40));
        jToggleButton1.setBackground(Color.red);
        jToggleButton1.setOpaque(true);
        jToggleButton1.setFont(new Font("Lucida Grande", 1, 18));
        jToggleButton1.setBorderPainted(false);
        jToggleButton1.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        jToggleButton1.setLayout(paneLayout2);
        jToggleButton1.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    try {
                        jToggleButton1_mouseClicked(e);
                    } catch (Exception f) {
                        f.printStackTrace();
                    }
                }
            });


    }

    void fileExit_ActionPerformed(ActionEvent e) {
        mFxcmGateway.logout();
        System.exit(0);
    }

    private void jToggleButton1_mouseClicked(MouseEvent e) throws Exception {

        AbstractButton abstractButton = (AbstractButton)e.getSource();
        boolean flag0s = abstractButton.getModel().isSelected();
        dc_EURUSD_S = new DecisionCenter_EURUSD_S();
        dc_EURUSD_S.aflags(flag0s);

        System.out.println("Action - flag0s = " + flag0s + "\n");

        if (flag0s == true) {
            jToggleButton1.setBackground(Color.green);

        } else {
            jToggleButton1.setBackground(Color.red);
        }
    }
}

Open in new window

I want to create one jPanel template and after just multiply it with different values.
Please advice.
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gbcbr

ASKER

Thank you, I tried all other except GridLayout, but this works good for me.
Just please tell me, how I can make template from this panel, so I can make for each pair ready panel with all necessary buttons and fields and just add it to the frame one by one as soon I'll need them?

Well, frankly this sort of thing never worked very nice for me in this way.
You probably want to create JTable for that, which is a lot more pain.
How many panels (lines)  total do you think there would be?
Is it a limited number?

Avatar of gbcbr

ASKER

>>How many panels (lines)  total do you think there would be?
Is it a limited number?
at the moment 10 lines and 11-12 columns
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gbcbr

ASKER

Thank you, most important for me now that I can adjust positions of elements.
I'll try also these to options.
Yes, let me know how it works.
Avatar of gbcbr

ASKER

OK