I have a TabFolder which was resized initially. Under the TabFolder is a TabItem and under that TabItem is a Button. The Button inherited the size of the TabFolder so it's huge. What's the best way to resize the Button? Using button.setBounds(...) doesn't work.
Here is the code snippet:
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TabFolder tabFolder = new TabFolder(container, SWT.NONE);
Dimension dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
TabItem tbtmNewItem = new TabItem(tabFolder, SWT.NONE);
tbtmNewItem.setText("1");
TabItem tbtmBrowse = new TabItem(tabFolder, SWT.NONE);
tbtmBrowse.setText("3");
Button btnNewButton = new Button(tabFolder, SWT.BORDER | SWT.CENTER);
btnNewButton.setAlignment(SWT.CENTER);
tbtmBrowse.setControl(btnNewButton);
btnNewButton.setText("Push");
tabFolder.setBounds(0, 0,dim.width-10,dim.height-10);
createActions();
initializeToolBar();
initializeMenu();
this.setPartName("Home");
}
I found a solution. I just removed the button from the control of the tab.
Removed:
tbtmBrowse.setControl(btnNewButton);
The button can now be resized independently or using setBounds when using a null layout.
So the Control you set on TabItem was a Composite? Or a Button?
The was to control the size of the button is to create a Composite and set that on the TabItem. Then you can add your button(s) to the Composite. You then set a layout on the composite to control how your button(s) are laid out. See http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html for more details on layouts.
EDIT:
To use it, you insert a composite between the tab folder and the button:
Composite page = new Composite(tabFolder, SWT.NONE);
page.setLayout(new GridLayout(1, false));
Button btnNewButton = new Button(page, SWT.BORDER | SWT.CENTER);
btnNewButton.setAlignment(SWT.CENTER);
btnNewButton.setText("Push");
tbtmBrowse.setControl(page);
You use layouts to control the sizes of child controls ... in this case, your button. See the Understanding Layouts article.
Related
I have a page created using Xamarin Forms. I want to add a toolbar at the bottom of the screen like an overlay but doesnt change the actual layout of the screen. It should just overlay above everything and always be at the bottom.
It should showup only when there is a particular event. SO it will be added dynamically.
Any ideas - or if you can send point me in the right direction. I do not want to use any nuget packages.
Have you tried to use AbsoluteLayout/Grid?
<Grid>
<StackLayout><Label Text="Your content"/></StackLayout>
<Button x:Name="toolbar" VerticalOptions="End" Text="Your toolbar" />
</Grid>
Show/hide the control based on your event.
If you could show the code of displayToolbar it would be easier to write a code that suits your needs, but it should be pretty easy even without the code :)
You could do this with a RelativeLayout, AbsoluteLayout or a Grid but I recommend doing it with a Grid because is much lighter than RelativeLayout and has a lot more functions than AbsoluteLayout.
So, make the root of every page that you want to use displayToolbar a Grid with one row and one column. Add the actual content of the page to that Grid as a child view.
Now comes the part that would be easier with your code. When you want to display the toolbar, add the toolbar view as a child of the root Grid with VerticalOptions set to LayoutOptions.End.
That's it. The toolbar will be added in front of every view of the page and if you want to dynamically remove the toolbar, remove the root Grid's last child.
The layout would be something like this:
Grid root;
internal SomePageConstructor()
{
root = new Grid
{
ColumnDefinitions =
{
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
},
RowDefinitions =
{
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }
}
};
root.Children.Add(actualPageContent, 0, 0);
Content = root;
}
void DisplayToolbar()
{
var toolbar = new StackLayout { VerticalOptions = LayoutOptions.End };
root.Children.Add(toolbar, 0, 0);
}
void RemoveToolbar()
{
root.Children.Remove(root.Children[1]);
}
Note: I did this directly on StackOverflow, code could need some corrections.
From this sample, you could do an animation of the toolbar coming from below the page or something like it. Just change the DisplayToolbar and the RemoveToolvar methods.
Obs. Method names on C# are PascalCased (every word is capitalized) so your displayToolbar is DisplayToolbar.
Hope it helps! :)
How can I add clicklistener to vaadin label, without putting into horizontal or vertical layout? I want to show tool tip on clicking of the label, not on mouse over.
That's not possible.
Putting it in a layout is really not that big of a deal, the following is all you need to do:
HorizontalLayout labelLayout = new HorizontalLayout();
labelLayout.addComponent(new Label("text"));
labelLayout.addLayoutClickListener( e -> <code that does something>);
If you don't want to do that you can use a third party add on which does exactly what you want. https://vaadin.com/directory#!addon/labelbutton
With it you can do:
LabelButton label = new LabelButton("text", event -> <do something>);
I recommend you use a button and add style borderless as shown on the code below. It will appear as a label.
VerticalLayout vertical = new VerticalLayout();
vertical.addComponent(new Label("Am the Hint..."));
PopupView popup = new PopupView(null,vertical);
Button b = new Button("Show Hint");
b.addStyleName(ValoTheme.BUTTON_BORDERLESS);
b.addClickListener((Button.ClickEvent event) -> {
popup.setPopupVisible(true);
});
addComponents(b, popup);
I have the following class which adds an image to a button and then adds the button to a panel
private PushButton button;
private AbsolutePanel panel = new AbsolutePanel();
private Image image = new Image("images/rectangle_blue.png");
public ExpandingRectangularButton(String text)
{
String width = "120px";
String height = "160px";
image.setWidth(width);
image.setHeight(height);
button = new PushButton(image);
panel.add(button, 0, 0);
panel.setWidth(width);
panel.setHeight(height);
initWidget( panel );
}
When I display an instance of ExpandingRectangularButton the button is truncated on the bottom. However if I take the panel out of the equation as follows
private PushButton button;
private Image image = new Image("images/rectangle_blue.png");
public ExpandingRectangularButton(String text)
{
String width = "120px";
String height = "160px";
image.setWidth(width);
image.setHeight(height);
button = new PushButton(image);
initWidget( button );
}
and just use the image and the button ( ie I call init() on the button ) then the image will display with no truncation. As I don't set the height of the button I assume it grows dynamically to accomodate it's child widget. Why does this not happen when I put the button onto the panel?
Quoting the Javadoc:
An absolute panel positions all of its children absolutely, allowing them to overlap.
Note that this panel will not automatically resize itself to allow enough room for its absolutely-positioned children. It must be explicitly sized in order to make room for them.
You can:
explicitly set the AbsolutePanel size;
remove the overflow: hidden property from it (workaround);
use panel.add(button, -1, -1) to position the button statically;
change the AbsolutePanel with one that naturally adapt its size (like almost any other Panel).
I'd prefer the last, but your use case is not clear.
hi i have created a user control.
now i want to add this control to a page e.g. when the user clicks a button (important is, that i dont want to add it direcly in xaml, i want to add id in the c# code section)
how to so this?
In your button's Click event, you could do something like:
MyControl control = new MyControl();
// Set whatever properties you need in your control here
LayoutRoot.Children.Add(control);
if (listBox1.Items.Count == 0)
{
Popup popup = new Popup();
WPCpopup po = new WPCpopup(popup);
popup.Width = System.Windows.Application.Current.Host.Content.ActualWidth;
popup.Child = po;
popup.VerticalOffset = 300;
popup.IsOpen = true;
}
WPCpopup is usercontrol
I'm new to WP7 and I want to know if there is any way to add items like a TextBlock to
a page dynamically using the .cs part??
Try this
var textBlock = new TextBlock();
// set some properties
YourMainContainer.Children.Add(textBlock); //
If you need more details just comment this
If you know the controls that you'd like to appear on the page dynamically, then I'd approach the problem by including those controls in the XAML and using the Visibility property on the controls to show and hide them. In Silverlight, the Visibility enumeration is limited to the values Visible and Collapsed, so when it isn't visible the it doesn't take up any space. You can control Visibility with data-binding by using a converter (search on "visibility bind converter") if you are intersted in pursuing that avenue. You can show/hide groups of controls by changing the Visibility of their parent control, such as StackPanel or custom control.
Try this one,
TextBlock txtmsg = new TextBlock();
txtmsg.Text = "New Program.";
txtmsg.Margin = new Thickness(10, 20, 10, 10);
txtmsg.TextWrapping = TextWrapping.Wrap;
txtmsg.FontSize = 28;
txtmsg.TextAlignment = TextAlignment.Center;
ContentPanel.Children.Add(txtmsg);