Skip to main content

Need more control of Form title bar

3 replies [Last post]
spint
Offline
Joined: 2008-06-17

I need a way to set more than just a String for the title bar of a Form.

Can you allow a user created Component for the title bar?

Maybe add a method to Form
public void setTitleBarComponent(Component cmp)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07

Hi spint,
i think you might be looking for getTitleComponent().setIcon(...);
Notice that you can style the title in any way you choose...

If you need something more elaborate you can just avoid setting the title and instead just place a custom component in the NORTH portion of a border layout. The reason for this is to keep the API simple for the common case.

Thanks,
Shai.

spint
Offline
Joined: 2008-06-17

I need something much more elaborate than the Label that getTitleComponent() provides. My title bar needs to contain multiple images, left and right justified text Strings, and other custom drawing ability.

I have already partially implemented your suggestion of creating my own container which has it's own content pane and title bar but it requires overriding almost every Form method. addComponent, removeComponent, setLayout, anything that references contentPane needs to be overridden so they get added to my new content pane instead of the default Form ContentPane.

Is there an easier way to do this that I'm missing?

vprise
Offline
Joined: 2003-11-07

The simplest way to do something like this is to just avoid the idea of a title and treat this as a component. So you can have a subclass of Form likewise:

public class MyForm extends Form {
private Container actualContent = new Container();
public MyForm() {
setLayout(new BorderLayout());
addComponent(BorderLayout.NORTH, createTitle());
addComponent(BorderLayout.CENTER, actualContent);
}

public Container getContent() {
return actualContent;
}
}

Now to use the form rather than add directly to the form do something like this:
frm.getContent().addComponent(...);

If you want to simplify this just create simpler methods like: add/remove/setContentLayout into your form that would delegate to actualContent.

Hope this helps.
Shai.