Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Swing absolute layout in BottomTab - is it possible?
 Post subject: Swing absolute layout in BottomTab - is it possible? Post rating: 0   New post Posted: Tue 09 Aug, 2011, 19:02 

User rating: 0
Joined: Mon 25 Jul, 2011, 14:27
Posts: 7
Location: UA
Here is the simplest demo code which is NOT work :(
package jforex;

import java.util.*;
import javax.swing.JPanel;
import java.awt.FlowLayout;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.GridLayout;

import com.dukascopy.api.*;

public class jfSwingTest implements IStrategy {
   private IEngine engine;
   private IConsole console;
   private IHistory history;
   private IContext context;
   private IIndicators indicators;
   private IUserInterface userInterface;

    private JTextField textField;
           
   public void onStart(IContext context) throws JFException {
      this.engine = context.getEngine();
      this.console = context.getConsole();
      this.history = context.getHistory();
      this.context = context;
      this.indicators = context.getIndicators();
      this.userInterface = context.getUserInterface();

        JPanel panel = userInterface.getBottomTab("Bottom Tab");
        //panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); // OK
        //panel.setLayout(new BorderLayout(0, 0)); // OK
        //panel.setLayout(new GridLayout(3, 3, 3, 3)); // OK
        panel.setLayout(null); // EMPTY
       
        textField = new JTextField();
        panel.add(textField);
        textField.setColumns(10);

   }

   public void onAccount(IAccount account) throws JFException { }

   public void onMessage(IMessage message) throws JFException { }

   public void onStop() throws JFException { }

   public void onTick(Instrument instrument, ITick tick) throws JFException {
        this.textField.setText(instrument+" "+tick.getAsk());
   }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { }
}


All comennted //panel.setLayout is works fine (I see in bottom tab refreshing TextField), but the last one, which must be an Absolute layout is not work (bottom tab is empty).

Where I am wrong? Haw can I use Absolute layout or any other layout from Eclipse WindowBuilder designer?


 
 Post subject: Re: Swing absolute layout in BottomTab - is it possible? Post rating: 0   New post Posted: Tue 16 Aug, 2011, 07:33 

User rating: 0
Joined: Mon 25 Jul, 2011, 14:27
Posts: 7
Location: UA
I am realy confused. Is this question so hard for support service? Is anybody here?


 
 Post subject: Re: Swing absolute layout in BottomTab - is it possible? Post rating: 0   New post Posted: Wed 17 Aug, 2011, 12:57 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/index.php ... ck_counter

P.S. For a fast response, please post a topic in a correct forum.


 
 Post subject: Re: Swing absolute layout in BottomTab - is it possible? Post rating: 0   New post Posted: Wed 17 Aug, 2011, 18:16 

User rating: 0
Joined: Mon 25 Jul, 2011, 14:27
Posts: 7
Location: UA
API Support wrote:
See:
https://www.dukascopy.com/wiki/index.php ... ck_counter

P.S. For a fast response, please post a topic in a correct forum.

Sorry... I am need not "fast response" but correct one ;)
In my code I show commented lines which is not work. Simple switching to another layout in the same panel produces unexpected result - all controls in this panel totaly dismiss :(
Can anyboby fix my code so it can display controls in all 3 commented examles of different layout? Or, if it is impossible - give me the link to any guideline where this moment is clearly described.


 
 Post subject: Re: Swing absolute layout in BottomTab - is it possible? Post rating: 0   New post Posted: Thu 18 Aug, 2011, 07:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
ForexTools wrote:
Can anyboby fix my code so it can display controls in all 3 commented examles of different layout? Or, if it is impossible - give me the link to any guideline where this moment is clearly described.
You need to "Call the Component class's setbounds method for each of the container's children." as of :
https://download.oracle.com/javase/tutor ... /none.html
The previously posted example does just that. In your case you would need to add the following 2 lines:
Insets insets = panel.getInsets();
textField.setBounds(25 + insets.left, 5 + insets.top, 100, 25);


 
 Post subject: Re: Swing absolute layout in BottomTab - is it possible? Post rating: 0   New post Posted: Thu 18 Aug, 2011, 08:07 

User rating: 0
Joined: Mon 25 Jul, 2011, 14:27
Posts: 7
Location: UA
Thanks. It can be a solution, but very poor.
I expected to use WindowsBuilder designer automaticaly generated code from eclipse. But WB uses layouts, not insets.
So main task - visualy draw form in WB and use it without any correction in jForex, can be done only for panel.setLayout(null). Other layouts is not supported.


 
 Post subject: Re: Swing absolute layout in BottomTab - is it possible? Post rating: 0   New post Posted: Thu 18 Aug, 2011, 08:51 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The use of insets is not the mandatory part, the use of Component.setBounds is. This restriction is set by java, not JForex. Thus you can use as well:
textField.setBounds(25, 5, 100, 25);
From a quick peek at your mentioned WindowsBuilder, apparenlty the designer uses the Component.setBounds for its components as well. Therefore in theory there should not be much problems in copying the source from the designer to the bottom tab source.


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com