swing - changing the maximize button behavior - swing

I am trying to replace the maximize button in my (swing) screen.
I want my frame to change it's size to my definition of max size and min size,
without the window moving its position.
I tried the following ( and encountered a problem in all )
1. Frame.setMaximumSize, Frame.setMinimumSize. did actually nothing.
2. tableFrame.addWindowStateListener(new WindowStateListener() {
public void windowStateChanged(WindowEvent e) {
then I resized the window
did actually pretty well job in managing the sizes - only that it jumped the screen to the top right corner every click .
(And all I need is to resize the window size when maximize )
3. obviously adding window listener on componentResized doesnt do the job because when I change the sizes to my wanted size - it enters an infinite loop.
thanks a lot

I think you're looking for Frame#setMaximizedBounds(): http://download.oracle.com/javase/6/docs/api/java/awt/Frame.html

Related

ChildViewController in UIContainerView has wrong height on initial load

I have a ViewController that has content in the top third and then a UIContainerView in the bottom two thirds of the view. The UIContainerView allows the user to rotate between three childViewControllers. Using AutoLayout, I have constrained the UIContainerView to the sides of the screen (widthAnchor), the bottom of the screen (bottomAnchor) and two thirds of the way up the screen (topAnchor).
In laying out content in the first childViewController, which appears on the initial load of the parent ViewController, I ran into difficulty. It appears that on that initial load, the childViewController view is given a view.frame.height equal to the height of the device. I set up my constraints to deal with that and the first screen displays fine.
The issue I am running into now is that when I rotate through the childViewControllers, the view.frame.height is set to the height of the ContainerView (which I would have suspected to be the case from the start). This causes the constraints in the first childViewController to "break".
Look at this behavior below.
Image #1: Initial load of the ParentViewController.
https://roryent.box.com/s/xhil4wk0ga5qoddhko5jxj3a1r4103h3
Image #2: Switching the childViewController.
https://roryent.box.com/s/9f2jj0l1waui3ekyplq4eae51m6wrqn5
Image #3: Coming back to the initial childViewController. The constraints "work" but are reacting to a different view.frame.height.
https://roryent.box.com/s/cj9ffyy3m9oh8f523l2vsdezo1frk12x
NOTE: I am creating the constraints in the ChildViewController class and trying to use the frame of that childViewController frame to do so.
I have attempted to move the methods for constraining the items into willLayoutSubviews() in the childViewController with no change.
I suspect that there is something wrong with where I am loading the different items.
I would expect the self.view.frame.height used in the childViewController code reflect the height of the UIContainerView that is displaying it. In my case the height should be .67 * UIScreen.Main.Bounds.Height.
I believe the issue was due to my implementation of the ContainerView and its corresponding childViewControllers.
I have rebuilt the feature following this tutorial and have not had any problems. https://cocoacasts.com/managing-view-controllers-with-container-view-controllers/

AS3 : Create a responsive mxml resize bitmapimage which resizes according to browser

I have a simple bitmap image 3px wide and 150px high included as the top banner in my layout.
<s:BitmapImage id="blueBanner" source="{this.bmpimg}" width="100%"/>
The rest of the content is centered below this.
When the page opens no matter the size of the browser window, the image always fills the width available.
I have a browser window resize handler that resets my main content below the banner to the center of the new window size and this works perfectly.
But no matter how many times the browser is resized, the BitmapImage will never stretch wider than the original window width.
I have tried every property and method of BitmapImage that I think could affect this in the resize handler but nothing I can find has any effect at all.
I cannot understand how it remembers the original stage width to begin with.
Its parent containers are all set to 100% width and there are no unusual skins or any other reference to this object in the whole project except in a function where it can be included in the layout or not, but this function is never called in this case.
Can anyone offer any clue as to why it won't stretch automatically?
Doug
Simple , just set the width to screen.width and you are good to go.
<s:BitmapImage id="blueBanner" source="{this.bmpimg}" width="{screen.width}"/>
Thanks for all the responses. In fact I solved the problem by adding the BitmapImage line to the Application Skin. Once it's here as well as in the layout it works. I have no idea why it needs to be in both places, but once it's set up like this everything works correctly.
Setting ScaleMode makes no difference and setting screen.width either in the blueBanner tag or later in the resizeHandler (because not always available when the tag is run) also makes no difference in my layout.
Doug

When and how to set window size using Tk

I'm writing a script to output things to a window comprising a Tkhtml widget and a text widget displayed above each other in a ttk::panedwindow. Both widgets are scrollable both vertically and horizontally. There's also a button allowing the user to clear the text widget.
I'm doing some of the development on a laptop running Ubuntu. The window manager allows for four desktop workspaces in a 2x2 array, and when the GUI is first displayed, the bottom fifth or so bleeds from the workspace I'm using into the one below. It's irritating to have to muck around resizing the window to make it short enough to fit onto the screen so I want to resize it.
(I think) I know approximately how to do this, i.e bind to an appropriate event so that I can run a script when the window is first displayed. (Reset the binding from within the script so that it only fires once.) I believed that the "appropriate event" was <Map>, but when the window was first mapped, the two widgets had zero height (as reported by [winfo height]). I tried binding to <Expose> and this seems to work, ([winfo height] returns sensible numbers,) so:
Question 1: Which event should I bind to?
When the binding fires, [wm geometry] reports the geometry as 815x1029+49+24, [winfo height] reports the two heights of the two widgets as 600 and 366, and [wm screenheight] returns a height of 800. I know there are various other bits and pieces in the GUI so I'm not surprised that there are 63 pixels unaccounted for in the initial layout. I assume that I need the same amount of space after resizing, so I should request a geometry of 815x737+49+24, but when I do, a sliver (approximately the lower horizontal scrollbar) still bleeds onto the next workspace.
By mucking around manually, I know that when everything fits nicely onto the screen the geometry should be 815x717+49+24, so I've added a fudge factor of 20 to the amount of space I allow for the "other bits and pieces of the GUI". This works fine but seems a little inelegant (massive British understatement :-) ), so:
Question 2: What have I missed, requiring use of a fudge factor?
I'm using Tk 8.6.1 on Ubuntu 12.04.5 LTS. I'm using version 0.9.7.12 of the Compiz window manager.
Update
It struck me that I ought to find the height of the various panes, rather than the Tkhtml and text widgets as that would account for the scrollbars and the "Clear" button. The pane heights are 615 and 409 initially, but this just means that I have to increase my fudge factor from 20 to 78 to get the request height to my desired value of 717. Is there any way to predict what height to request for the toplevel containing my paned window in order to get that toplevel to fill the screen?
I recommend binding to <Map>. I would wait for all of: the paned window, the main tkhtml window, the text window and the scrollbars to be mapped before trying to adjust heights.
For Linux, the [winfo screenheight .] does not know about any panels that are configured, so you have to subtract those. You can get the actual screenheight available by creating a window, doing a wm attributes . -zoomed 1, then getting the geometry of the window.
The title bar and borders of the window take up space. The space needed for these can be calculated by comparing the output from [winfo geometry .] and [wm geometry .].
There is also the panedwindow sash height and any margins and padding.
You can calculate the total of these by subtracting the panedwindow heights from [winfo height .].
Here is one method that would always work, however, it is not very attractive, as the user would see the windows flashing as they change size.
Maximize the window (wm attributes . -zoomed 1)
Get the window geometry and parse out the screenheight.
De-maximize the window (wm attributes . -zoomed 0)
Get the window geometry and replace the screenheight
with the maximized screenheight.
Set the window geometry.

Width turns out too much

I'm trying to build some kind of menu that overlaps when called upon (by pressing the menu button).
Since this will be a mobile app I want all measures to be responsive and thus written in percentage instead of pixels.
I'm in some way trying to make a slide in menu like the Facebook App has.
My solution to this is to have a side menu that is 0% width. When the menu-button is pressed the menu will expand to 70% of the device's screen width, thus covering 70% of the width.
I've been trying to get it right by doing this
<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void {
trace( stage.fullScreenWidth, stage.fullScreenHeight );
trace(meny.width);
if (meny.width !== 0) {
meny.width = 0;
} else {
meny.width = 0.5*stage.fullScreenWidth;
}
}
]]>
</fx:Script>
When I debug the trace's show's me the correct values. In this case emulating iPhone 4 it gives me: 540 (width) 960 (height) and 270 (meny.width).
However, even tho the calculation has been correct (270 is 50% of 540) the width of the meny will cover more than half of the screen, approximately 80%~
Why is it doing this and what's the solution? The debugging console is giving me the correct values but it isn't turning out to work.
I also tried on an Android device plugged in and the same issue, so it's not the emulation being a problem.
Any solutions appreciated.
I suggest you to use sizes of application's width instead of stage width:
menu.width=parentApplication.width
You don't need to deal with stage sizes until you add some global event listeners or use something like StageWebView or StageVideo
You can read this articale about mobile apps auto scaling for more details.

resizing widget in pygtk

I have a scrolled window, which contains a drawing area in pygtk. I would like to change the size of the drawing area, and keep the scrolled window as it is. I don't find a function that works on widgets. I can get the size and so on, but I can't set it. Could someone give me a pointer to the solution?
Thanks,
v923z
It sounds like .set_size_request() is what you need. An example would be:
drawingarea.set_size_request(400, 400)
The values are the width and height of the canvas. Assuming you're ScrolledWindow is setup correctly, the scrollbars should adjust automatically to the size of the DrawingArea.