Scala Swing: Changing BorderPanel central component new Component not visible - scala

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().

Related

How to handle window resizes in GTK4?

I am trying to build a virtualized grid container to display 100k+ files in PyGTK 4 on Fedora 35. I succeeded in creating the layout and scrolling support which works beautifully.
In order to support resizing of my application window, I need to react to changes its size. I already connected to the notify signal of the window and handle the default-width, default-height, maximized and unmaximized events to update the geometry of my layout. However, everytime I invoke get_width() of my widget/app window after the maximized event I only get the width before the window was maximized! Is this by design?
I've been trying pretty hard but I fail to come to a working solution for this simple problem. Can anyone help me?
Edit
Here is some code to outline how I am trying to measure the window size. I modified the code to use connect_after instead of connectas proposed by #GüntherWagner. However, the behavior is the same for both methods:
class TestLayout(Gtk.ScrolledWindow):
def on_realize(self, widget):
...
self.get_root().connect_after('notify', self.on_notify)
def on_notify(self, widget, param):
if param.name in [..., 'maximized', 'unmaximized']:
self.draw()
def draw(self):
self.width = self.get_width()
self.height = self.get_height()

Opening frame that is under the JavaFX program category

Most of program is using JFrames throughout the application for all the different windows that can appear. However, I have to play an instructional video for the user inside a JFrame. I couldn't find a way to do this, so I had to make a JavaFX program. Is there a way to get directly from one of my JFrames to the JavaFX window?
I've been using syntax like this to open up other JFrame:
dispose();
paths pths = new paths();
pths.setVisible(true);
However, when trying to open up the JavaFX using the above code, I get errors. I also can't create a new JavaFX inside an already existing project.
I am not sure to understand your problem but in order to create a new frame in JavaFX. You have to create a new class with a new stage. Let's say you create a new class "newFrame" with the code below.
public void show(Stage stage){
//define your root
double width = 200;
double height = 200;
Scene scene = new Scene(root, width , height);
stage.show();
}
You can show the new frame by using :
newFrame NT = new newFrame();
NT.show();

How to change the background of a ScrollPane (JavaFX/ScalaFX)?

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")

Freezing the tool tip after clicking on it

I am trying use org.eclipse.jface.window.DefaultToolTip to display some UI components like checkbox,radio buttons placed on composite. When user clicks on a text, the tooltip with pops up to and displays the UI components.
Issue: I want to freeze tool tip once user clicks inside this tooltip. Using toolTip.setHideOnMouseDown(false); I am able to check/un-check the check boxes/radio buttons as long as I am inside the tool tip area. Once mouse pointer exits the tool tip area, the tooltip disappears. How can this be avoided. I am looking for similar behaviour which is available for eclipse tooltips( javadoc, method definition). In Eclipse tooltip, if we click/press f2, tooltip will remain active until we click outside of the tooltip area.
Edit: I also tried to use Eclipse Plugin Spy on tooltip, but no success.
Any thoughts.
What Eclipse does when F2 is pressed is to create a new Shell with exactly the same size and contents as the tooltip and closes the original tooltip.
I use code like the following in an extended tooltip class:
/**
* Switch from tool tip to a normal window.
*/
private void showWindow()
{
if (_control.isDisposed())
return;
final Shell shell = new Shell(_control.getShell(), SWT.CLOSE | SWT.ON_TOP | SWT.RESIZE);
shell.setLayout(new FillLayout());
createBody(shell);
final Point currLoc = _parent.getShell().getLocation();
final Rectangle client = _parent.getClientArea();
final Rectangle bounds = shell.computeTrim(currLoc.x, currLoc.y, client.width, client.height);
shell.setBounds(bounds);
shell.open();
// Hide the tool tip window
hide();
}
_control is the control passed to the constructor.

gtkmm button not maintaining size and location

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)