I want to change the background color of a ScrollPane. This is part of my code where I try to do that:
val sp=new javafx.scene.control.ScrollPane(new Group(new Text(...)))
sp.setPannable(true)
sp.setStyle("-fx-background-color: blue")
sp.setBackground(new Background(Array(new BackgroundFill(Color.DARKCYAN,new CornerRadii(0),Insets(0)))))
Text appears OK, but both attempts to change the background color have no effect, using:
Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_05).
Inspecting with Scenic View, I discover that two StackPanes have unexpectedly appeared in the scene graph below the ScrollPane, so the hierarchy is:
ScrollPane //which I created
StackPane //UNEXPECTED -- clips the content
StackPane //UNEXPECTED -- full size content
Group //which I created
Text //which I created
If I change the background of either of the StackPane-s to, say, "-fx-background-color: blue" (with Scenic View), it has effect, but not the style of the ScrollPane. But how to do that from code? If I do
println(sp.content())
, it says
Group#567fa81a
Is there a simple way to access the StackPanes or change the background? I could "slap in" a big filled rectangle, but that seems ugly and complicates resizing, what is wrong with the background proper?
Similar to JScrollPane, JavaFX ScrollPane has a StackPane container within itself called viewport. So to set background for your ScrollPane use this CSS rule (i.e. to set red background color):
.scroll-pane .viewport {
-fx-background-color: red;
}
sp.setStyle("-fx-background: blue")
instead of:
sp.setStyle("-fx-background-color: blue")
Related
When I place JavaFX object inside a container, for example some checkboxes inside an hbox:
The scenebuilder controls for each checkbox show the container object in the menu (and different settings are shown here depending on the actual container):
But changing the "margin" value here, for example, clearly affects the individual checkbox and not the HBox. For example, setting only the middle checkbox to have a left margin of 20 yields a change to only the middle checkbox:
So why is that menu area labeled with the container name? I fear I am missing some fundamental design aspect by not understanding this.
They are properties of the control that are specifically available when its parent is an HBox. They correspond to the static methods HBox.setXXX(node, value), e.g. HBox.setHgrow(...).
If you put the check box in an AnchorPane instead, for example, you would see "Anchor Pane Constraints" instead of "HBox Constraints" and you would have options including "TopAnchor", "LeftAnchor" etc., corresponding to the static AnchorPane.setXXX(node, value) methods.
I'm using custom cursors and it need to be differ in some components in my screen.
When I set the cursor for Accordion, it doesn't effects title headers but effects the body of each TitledPanes. I even tried to set the cursor for each TitledPane but it doesn't effect the title header. I'm using following way to change the cursor.
ImageCursor cursor_title = new ImageCursor(cursorImg_title,cursorImg_title.getWidth() / 2,cursorImg_title.getHeight() / 2);
accordionBody.setCursor(cursor_title);
Is there a way to change the cursor in title bar of a JavaFX Accordian?
More....
I have changed the padding of title bars using css as follows. Hope it doesn't have any relation to the problem.
.titled-pane > .title {
-fx-padding: 30;
}
A TitledPane is divided into two parts :
Title
Content
When you are setting the Cursor on the Accordion, it delegates it to the content of each TitledPane, but leaves the Title. This is by design.
To force your application to change the cursor on the title as well, we need to set it on each of these nodes. We can fetch all the nodes by using the lookupAll() on the accordion and passing the styleclass they use i.e. .title. Make sure you use this after the scene graph is visible.
accordion.lookupAll(".title").forEach(node -> node.setCursor(Cursor.CLOSED_HAND));
You can use your custom cursor in place of CLOSED_HAND.
I am trying to remove borders of the portlet as well as the panel.
Below is my code snippet,
public class TestViewImpl extends ViewImpl implements TestViewPresenter.MyView{
private PortalLayoutContainer portal;
#Inject
public TestViewImpl (){
portal = new PortalLayoutContainer(1);
vp = new VerticalLayoutContainer();
portal.getElement().getStyle().setBackgroundColor("white");
portal.setColumnWidth(0, 1);
portal.setBorders(false);
ContentPanel portlet = new Portlet();
portlet.getHeader().setVisible(false);
portlet.setBorders(false);
portlet.setBodyBorder(false);
portlet.add(vp);
portlet.setResize(true);
portlet.setBodyStyle("backgroundColor:white;");
portal.add(portlet, 0);
But somehow the border is always visible.How do I remove the border ? Please help.
Thanks in advance
With that code I can get the borders to disappear (with small alterations to container instantiation). Where are those containers coming from? Are you using UI Binder, if so could you post that code as well.
The blue section that is left is the background from the header. (Hide header hides the text)
If you really need to remove the outline border (which is a background image actually), you can try something like this:
Element e = portlet.getElement().getFirstChildElement();
e.getStyle().setBorderWidth(0, Unit.PX);
Here is the screenshot of the result:
It's not going to be easy, but this is the only way (from what I know and tried already), you going to need developer tools on browser (i.e. firebug) to do inspection, and predict what element to get and what attribute to remove. The code I provide above are just example how we can remove the top outline border, and for the rest you can tried it by yourself. Goodluck :-)
I'm changing the centre area on a Scala Swing Border Panel. The old component disappears, but the new component does not appear, until I resize the window manually with the mouse. I've tried using different components and repainting, but nothing makes the new component appear except manually resizing the window with the mouse.
def splitDisp(mapCanv: VistaIn): Unit =
{
val canv2 = newMapCanv
panel.layout(canv2) = BorderPanel.Position.Center
canv2.repaint
thisScn.repaint //ref to the Frame instance
panel.repaint
thisScn.repaint
canv2.repaint
}
I'm using 2.10.0M5 in Windows 7.
Try calling revalidate() and then repaint().
I have created two gtkmm button and added to HBox object. I called pack_end, and maintained the size as 21,20. But, the sizes are not maintained. Here is the code i have written and the window that i got while running the program.
Note: MYWindow is subclass of Gtk::Window
void MYWindow::customizeTitleBar()
{
//create a vertical box
Gtk::VBox *vBox = new Gtk::VBox(FALSE,0);
//create a horizontal box
Gtk::HBox *hBox = new Gtk::HBox(TRUE,0);
hBox->set_border_width(5);
//create title bar image
Gtk::Image *titleBarImage = new Gtk::Image("src/WindowTitleBar.png");
titleBarImage->set_alignment(Gtk::ALIGN_LEFT);
// hBox->pack_start(*titleBarImage,Gtk::PACK_EXPAND_WIDGET,0);
//create cloze button for window
mButtonClose = new Gtk::Button;
(*mButtonClose).set_size_request(21,20);
Gtk::Image *mImage = new Gtk::Image("src/Maximize.jpeg");
(*mButtonClose).add(*mImage);
(*mButtonClose).set_image_position(Gtk::POS_TOP);
// connecting close window function when cliked on close button
//(*mButtonClose).signal_clicked().connect( sigc::mem_fun(this, &MYWindow::closeWindow));
hBox->pack_end(*mButtonClose,Gtk::PACK_EXPAND_WIDGET,0);
Gtk::Button * mBtton = new Gtk::Button;
mBtton->set_size_request(21,20);
Gtk::Image *img = new Gtk::Image("src/Maximize.jpeg");
mBtton->add(*img);
mBtton->set_image_position(Gtk::POS_TOP);
hBox->pack_end(*mBtton,Gtk::PACK_EXPAND_WIDGET,0);
vBox->add(*hBox);
//drawing area box
Gtk::HBox *hBoxDrawingArea = new Gtk::HBox;
Gtk::DrawingArea *mDrawingArea = new Gtk::DrawingArea;
hBoxDrawingArea->pack_start(*mDrawingArea,Gtk::PACK_EXPAND_WIDGET,0);
vBox->add(*hBoxDrawingArea);
//status bar hBox
Gtk::HBox *hBoxStatusBar = new Gtk::HBox;
vBox->add(*hBoxStatusBar);
this->add(*vBox);
this->show_all();
}
I am not yet a gtk expert (but I'm learning), here's one thing you can try, which is what I've been doing.
Make a little standalone project using glade. Glade makes it really easy to screw around with all the packing settings so you can immediately see the effects of your changes.
I think in the case of resizing the window, you'll have to save the glade file and run your program (using gtkbuilder to render the glade file) and manually resize the window to see the effect, but once you make the standalone project, you can use it for other gtk testing.
And if you're like me, you'll get swayed by the wonderfulness that is glade and build your whole system that way.
But basically, it sounds like a packing issue, because I've got buttons that don't resize all over the place.
As for not moving, I'm not sure you can do that, but again I'm not an expert. I think you should be able to pin the size of some if not all of the hbox pieces so that the button inside them will not move, but I'm not sure what happens if you don't have any hbox parts that can't be variably sized to take up the slack when you grow the window.
Again, sounds like something fun to try in glade. :-)
I think you pack to FALSE , Maybe this is the problem :
Gtk::HBox *hBox = new Gtk::HBox(TRUE,0)
I use python gtk with something like this:
box1.pack_start(box2,False)