I have NatTable with column and row headers, and use CornerLayer for it. How to make row and column headers resizable like any other column or row?
You need to register the necessary bindings to the header regions
gridLayer.addConfiguration(new AbstractUiBindingConfiguration() {
#Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerFirstMouseMoveBinding(
new ColumnResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 0),
new ColumnResizeCursorAction());
uiBindingRegistry.registerFirstMouseDragMode(
new ColumnResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 1),
new ColumnResizeDragMode());
uiBindingRegistry.registerFirstMouseMoveBinding(
new RowResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 0),
new RowResizeCursorAction());
uiBindingRegistry.registerFirstMouseDragMode(
new RowResizeEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 1),
new RowResizeDragMode());
}
});
Related
Hello Everyone,
I have 2 Groups and each group has 3 Label and Text combinations, as you can see from the above Image.
I would like the text field to grab as much as space possible.hence, I have used grab 'true' only for the text field.
These label and text fields are well aligned inside their own group/composite.
But, when these 2 Groups are considered as a whole, the label and text fields are out of alignment.
Is there a way to align these label and text fields across multiple Groups?
is there a way to align these labels and text fields, without declaring each groups having equal column width, and specifying the number of columns label and text fields occupy?
Below is the code I have used for creating the below groups.
private void createFirstGroup(Composite parent) {
Group firstGroup = new Group(parent, SWT.NONE);
firstGroup.setText("first group");
GridDataFactory.fillDefaults().grab(true, false).applyTo(firstGroup);
GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(firstGroup);
String[] labels = new String[]{"Kwd","Variable","Value"};
for(int index=0;index<labels.length; index++){
Label label = new Label(firstGroup, SWT.NONE);
label.setText(labels[index]);
GridDataFactory.fillDefaults().applyTo(label);
Text textField = new Text(firstGroup, SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, false).applyTo(textField);
}
}
private void createSecondGroup(Composite parent) {
Group secondGroup = new Group(parent, SWT.NONE);
secondGroup.setText("second group");
GridDataFactory.fillDefaults().grab(true, false).applyTo(secondGroup);
GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(secondGroup);
String[] labels = new String[]{"Count","Upper Comment","Lower Comment"};
for(int index=0;index<labels.length; index++){
Label label = new Label(secondGroup, SWT.NONE);
label.setText(labels[index]);
GridDataFactory.fillDefaults().applyTo(label);
Text textField = new Text(secondGroup, SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, false).applyTo(textField);
}
}
I have a row in my header, which looks good, but I need to add another String in the same row, so it is on the right side of it
When I try to add that String in the same cell, everything loses the alignment
private void addHeader(PdfWriter writer) {
PdfPTable tableHeader = new PdfPTable(2);
try {
// set defaults
header.setWidths(new int[] { 20, 12, 12 });
header.setTotalWidth(527);
header.setLockedWidth(true);
header.getDefaultCell().setFixedHeight(5);
header.getDefaultCell().setBorder(Rectangle.BOTTOM);
header.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY);
// add text
PdfPCell text = new PdfPCell();
text.setPaddingBottom(12);
text.setPaddingLeft(8);
text.setBorder(Rectangle.BOTTOM);
text.setBorderColor(BaseColor.LIGHT_GRAY);
text.addElement(new Phrase("Hi", new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD)));
text.addElement(new Phrase("", new Font(Font.FontFamily.HELVETICA, 8)));
text.addElement(new Phrase("Hi" + "CVE-2017-2018", new Font(Font.FontFamily.HELVETICA, 9)));
header.addCell(text);
// add image
Image logo = Image.getInstance(App.class.getResource(LOGO_2));
header.addCell(logo);
PdfPCell cveTitle = new PdfPCell();
cveTitle.setPaddingBottom(15);
cveTitle.setPaddingLeft(8);
cveTitle.setBorder(Rectangle.BOTTOM);
cveTitle.setBorderColor(BaseColor.LIGHT_GRAY);
cveTitle.addElement(new Phrase("3 Cell", new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD)));
header.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
header.addCell(cveTitle);
}
CVE-2010-2016
Is just what I want to do, leave it on the right side
Update
The solution was to add a new value to the array, corresponding to a new cell, and also instantiating PdfPCell again, thks
Just from the classname PdfPTable, I can tell the iText version you are using is pretty outdated.
Please consider switching to a newer version. Latest version is iText7.
I think what you're looking for is colspan and rowspan.
Have a look at the tutorial:
http://developers.itextpdf.com/examples/tables/clone-colspan-and-rowspan
I'm trying to remove a Widget from a Gtk.FlowBox by destroying the widget, however there is a gray box left in place. Any idea how I can remove the gray box so that the adjacent widget falls into place after the removal of the widget.
The following is how the widgets are packed:
1- Two Images(from pixbuf) and Label are added to a OverlayImage
2- Overlay Image is added to a EventBox
3- EventBox is added to the FlowBox
I have tried the following methods:
1- Destroy the EventBox
2- Obtain and destroy all children of Overlay Image and then destroy OverLay Image and EventBox
In both case, the widget is removed but a empty area stays in its place which is grey when clicked, but does nothing - see picture.
How do I remove this empty space, so that the next widget automatically falls into the place where the widget was removed and the next widget falls into its place and so on.
The code is available here and the "removeSelectedBooksFromLibrary" is the method which is removing the EventBox selected by the user from the FlowBox
This is the code to add widgets from the FlowBox
https://github.com/babluboy/bookworm/blob/master/src/bookworm.vala#L589
This is the code to remove widgets from the FlowBox
https://github.com/babluboy/bookworm/blob/master/src/bookworm.vala#L512
Thanks in advance
Here is a working example with the solution added, which removes the widget and its parent.
public class FlowBoxIssue : Gtk.Window {
public static int main (string[] args) {
Gtk.init (ref args);
FlowBoxIssue window = new FlowBoxIssue();
window.show_all ();
Gtk.main ();
return 0;
}
public FlowBoxIssue () {
this.title = "FlowBox Issue";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (800, 600);
Gtk.FlowBox library_flowbox = new Gtk.FlowBox();
Gtk.Box library_mainbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 20);
Gtk.ScrolledWindow library_scroll = new Gtk.ScrolledWindow (null, null);
library_scroll.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
library_scroll.add (library_flowbox);
Gtk.Overlay aOverlayImage1 = new Gtk.Overlay();
Gtk.EventBox aEventBox1 = new Gtk.EventBox();
Gtk.EventBox aEventBox2 = new Gtk.EventBox();
Gtk.EventBox aEventBox3 = new Gtk.EventBox();
try{
Gdk.Pixbuf aBookCover1 = new Gdk.Pixbuf.from_file_at_scale("cover.png", 200, 250, false);
Gtk.Image aCoverImage1 = new Gtk.Image.from_pixbuf(aBookCover1);
aOverlayImage1.add(aCoverImage1);
Gtk.Label overlayTextLabel1 = new Gtk.Label("Label 1");
aOverlayImage1.add_overlay(overlayTextLabel1);
aEventBox1.add(aOverlayImage1);
library_flowbox.add (aEventBox1);
}catch(Error e){
}
Gtk.Overlay aOverlayImage2 = new Gtk.Overlay();
try{
Gdk.Pixbuf aBookCover2 = new Gdk.Pixbuf.from_file_at_scale("cover.png", 200, 250, false);
Gtk.Image aCoverImage2 = new Gtk.Image.from_pixbuf(aBookCover2);
aOverlayImage2.add(aCoverImage2);
Gtk.Label overlayTextLabel2 = new Gtk.Label("Label 2");
aOverlayImage2.add_overlay(overlayTextLabel2);
aEventBox2.add(aOverlayImage2);
library_flowbox.add (aEventBox2);
}catch(Error e){
}
Gtk.Overlay aOverlayImage3 = new Gtk.Overlay();
try{
Gdk.Pixbuf aBookCover3 = new Gdk.Pixbuf.from_file_at_scale("cover.png", 200, 250, false);
Gtk.Image aCoverImage3 = new Gtk.Image.from_pixbuf(aBookCover3);
aOverlayImage3.add(aCoverImage3);
Gtk.Label overlayTextLabel3 = new Gtk.Label("Label 3");
aOverlayImage3.add_overlay(overlayTextLabel3);
aEventBox3.add(aOverlayImage3);
library_flowbox.add (aEventBox3);
}catch(Error e){
}
Gtk.Button delete_button = new Gtk.Button.with_label("Delete Pix");
delete_button.clicked.connect (() => {
//This is the line which resolved the issue - get the parent of the widget and destroy it and then destroy the widget
aEventBox2.get_parent().destroy();
aEventBox2.destroy();
});
library_mainbox.pack_start(library_scroll, true, true, 0);
library_mainbox.pack_end(delete_button, true, false, 0);
this.add(library_mainbox);
}
}
Every time you add a child widget to a GtkFlowBox, the flow box widget will add an implicit child widget in between, for event handling and styling purposes — as the documentation for GtkFlowBox states:
Although a GtkFlowBox must have only GtkFlowBoxChild children, you can add any kind of widget to it via gtk_container_add(), and a GtkFlowBoxChild widget will automatically be inserted between the box and the widget.
This means that the line:
library_grid.add(aEventBox);
is really equivalent to:
var flowbox_child = new Gtk.FlowBoxChild();
flowbox_child.add(aEventBox);
library_grid.add(flowbox_child);
If you want to remove a widget from a GtkFlowBox and you only keep a reference to the child you added, you will need to retrieve its parent and remove that from the GtkFlowBox:
aEventBox.get_parent().destroy();
// or
library_grid.remove(aEventBox.get_parent());
I've created a FlexTable, and I want to center it horizontally within a parent FlowPanel, like:
FlexTable ft = new FlexTable();
ft.add(0, 0, new Label());
ft.add(0, 1, new Orange());
ft.add(0, 2, new Label());
FlowPanel parent = new FlowPanel();
parent.add(ft); // how can I horizontally center the table in this div?
The content of the table is narrower than the parent FlowPanel (which is width:auto, the whole width of the browser), but the table is left-aligned right now,
Thanks
Two options:
parent.getElement().getStyle().setTextAlign(TextAlign.CENTER);
or
ft.getElement().getStyle().setProperty("margin", "0 auto");
You can use CSS styles instead, of course.
First of all? Which version of GWT are you using? The reason am asking this question, there is no method in FlexTable that is similar to add (int, int, Widget ) you have used in the latest version.
However, you can use the following code.
FlexTable ft = new FlexTable();
ft.setWidget(0, 0, new Label("a"));
ft.setWidget(0, 1, new Label("b"));
ft.setWidget(0, 2, new Label("c"));
FlowPanel parent = new FlowPanel();
parent.setSize("100%", "100%");
parent.add(ft);
parent.getElement().getStyle().setProperty("TextAlign", "center");
// If you are using Firefox :
//parent.getElement().getStyle().setProperty("TextAlign", "-moz-center");
RootLayoutPanel.get().add(parent);
If you dont't wish to mention the style in the java code, you can always use CSS like
parent.addStyleName("myStyle");
In CSS
.myStyle{
text-align : center;
}
I'm trying to configure a dialog window like so:
#Override
protected Control createDialogArea(Composite parent) {
GridLayout dialogAreaLayout = new GridLayout();
dialogAreaLayout.numColumns = 2;
parent.setLayout(dialogAreaLayout);
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
gridData.minimumWidth = 300;
// the label in the first row should span across both columns
gridData.horizontalSpan = 2;
Label headlineLabel = new Label(parent, SWT.NONE);
headlineLabel.setText("example test");
headlineLabel.setLayoutData(gridData);
// the rest should be ordered in two columns
gridData.horizontalSpan = 1;
companyLabel = new Label(parent, SWT.NONE);
companyLabel("company");
companyTextfield = new Text(parent, SWT.BORDER);
companyTextfield(gridData);
...
What I'm trying to accomplish is a label in the first line, that spans across both columns and have the following fields be ordered in pairs per line. What I get with this is, that the lable (that should be left in second line) is right in first line, just as the label wouldn't span across two columns. Can anybody see, what I'm doing wrong?
Thanx again!
After setting the layoutData to headlineLabel, you are setting the horizontalSpan to 1. You need to create a new LayoutData object for every SWT widget. It is not possible to reuse them after setting them.