|By Phil Herold||
|August 10, 2005 11:00 AM EDT||
This article presents a Java/Swing component implementation of a feature that is ubiquitous in nearly all desktop applications, particularly Windows applications - an area in the lower right portion of a window (Frame) that can be used to resize the window.
Of course, a window can be re-sized with most desktop managers by dragging the lower-right edge - the additional component simply serves as a visual indicator of the resize capability, and also increases the margin of error for the mouse drag.
Typically this component is placed in a status or message area at the bottom of a window. I demonstrate my solution in the context of a very simple (and barely func-tional) Web browser. I also introduce a technique in which a Frame/JFrame/JInternalFrame can exhibit "continuous layout" behavior as it is resized.
The component is called Frame-Resizer. It subclasses JComponent and has two main jobs that it performs. First, it draws itself and, second, it handles mouse events so that it can both change the mouse cursor (on mouse enter/leave) and resize the window (on mouse press/drag/release). FrameResizer can be used to resize a Frame, JFrame, or JInternalFrame, each of which has a common ancestor of java.awt.Container in the component class hierarchy. So constructors for FrameResizer take a Container argument as follows:
public FrameResizer(Container parent);
public FrameResizer(Container parent, boolean useContinuousLayout);
Figure 1 shows the FrameResizer in its typical context, at the lower right edge of a window, as part of a status/message area.
FrameResizer draws itself in the paintComponent() method as shown in Listing 1. There are seven "ribs" that make up the component.
A rib is one of the raised "bumps" in the component visual; it's actually just two 2x2 pixel rectangles drawn in different colors offset slightly from each other. You can see this in the exploded view of the FrameResizer in Figure 2.
Much of the interesting FrameResizer code is in the MouseInputListener inner class that the component adds to itself. In the mouseEntered() and mouseExited() methods, the cursor is changed to Cursor.NW_RESIZE_CURSOR and the default Cursor, respectively. In the mousePressed() method (see Listing 2), the mouse location is converted to actual screen coordinates, and the relative location from edge of the window (the Point mouseAdjust) is calculated.
In the mouseDragged() method (see Listing 3), the current mouse position is again converted to absolute screen position, and the new bounds of the parent Container (Frame/InternalFrame) are recalculated based on the original mouse location.
The mouseReleased() method calls mouseDragged() for a final calculation, and then "validates" the parent container. Since FrameResizer supports either an external Frame or a JInternalFrame, the validate() method does the appropriate validation and invokes the repaint() method (see Listing 4). This needs to be done at the end of the AWT EventDispatchThread (thus the use of SwingUtilities.invokeLater()). This method is declared static so it can be re-used for the "continuous layout" functionality (see below).
This concept is familiar to Swing developers who use JSplitPane - it's the ability to have internal components validate and repaint as the container is resized (in real time). Unfortunately, when a top-level Java desktop window is resized, this doesn't happen, as the validate/repaint messages are not sent to the underlying Container until resizing (via mouse dragging) is complete. Figure 3 is a capture of our browser window during the mouse drag. You can see how the contents of the window are not "stretched' to fit the bounds of the Frame - this is done when the mouse is released.
Ideally you want the contents of the window to stretch to the frame bounds during resizing. This capability is evident in most non-Java top-level desktop windows.
The trick to doing this in Java is to use a Timer to periodically check the current bounds of the window (Frame), and if it has changed since the last interval, send the validate/repaint messages to the Frame. You can see how this is done in Listing 5. I coded it as a static method in FrameResizer so this functionality can be used independently of the component.
The code uses a static HashMap (continuousLayoutWindows) so it can be used for multiple windows in a multi-frame application. It lazily initializes this HashMap. In the map it stores the current Container bounds keyed by the Container. If the current bounds are different than what is in the map, the current bounds are saved and the validate and repaint messages are sent to the Container (our static validate() method from before). That's all there is to it. I use 100 milliseconds (hard-coded) as my timer interval - feel free to experiment with this number (or parameterize it).
You can specify whether or not "continuous layout" is used by the FrameResizer in its constructor (the default is true). Note that one drawback to "continuous layout" in this context is the flicker that occurs during the repaint. This is unfortunately unavoidable. Also note that the continuous layout behavior is not required if you are using the FrameResizer in the context of a JInternalFrame.
In this article I presented a custom Swing component that can be used to help provide a customary look and feel to a Frame or JInternalFrame. I've also introduced the concept of "continuous layout" to top-level Java desktop windows and shown how this can be implemented. The source code for this article can be downloaded from http://jdj.sys-con.com.
|Phil Herold 09/28/05 10:43:13 AM EDT|
The link for the code to this article has been fixed. Here's the direct link:
This contains a jar file with both source and class files. If your run the jar with javaw, it will run the "Lame Browser" window that is shown in the article.
|Phil Herold 09/26/05 09:59:47 AM EDT|
Someone in a private e-mail pointed out that Toolkit.setDynamicLayout() will accomplish the same thing as the timer/validate-paint technique used in my article. I haven't tried it, but you might look at that as well.
|Michael Bushe 08/12/05 08:05:03 PM EDT|
Brilliant!!! I've been writing fancy Swing apps for a long time and never even considered that there was a way around the gray-screen-as-you-resize problem. Very slick, very thorough. An icon for this was meticulously created by Jonathan Simon here:
|Bill Winspur 08/12/05 06:10:43 PM EDT|
Very interesting article - unfortunately I cant find a link to the source code in the article, or on http://jdj.sys-con.com . Can somebody provide it?
SYS-CON Events announced today that Akana, formerly SOA Software, has been named “Bronze Sponsor” of SYS-CON's 16th International Cloud Expo® New York, which will take place June 9-11, 2015, at the Javits Center in New York City, NY. Akana’s comprehensive suite of API Management, API Security, Integrated SOA Governance, and Cloud Integration solutions helps businesses accelerate digital transformation by securely extending their reach across multiple channels – mobile, cloud and Internet of Things. Akana enables enterprises to share data as APIs, connect and integrate applications, drive part...
Apr. 26, 2015 05:00 AM EDT Reads: 2,050
BroadSoft on Tuesday announced that it is a recipient of the 2014 Frost & Sullivan Market Leadership Award in the Hosted/Cloud Internet Protocol (IP) Telephony market for Latin America. According to Frost & Sullivan market research, the Latin America (LATAM) hosted/cloud Internet Protocol (IP) telephony market, including integrated unified communications and collaboration (UC&C) applications, is currently experiencing a rapid growth trajectory and is expected to exhibit a tenfold rise in annual revenues in the 2013-2020 period. With more than 600 cloud deployments internationally, BroadSoft w...
Apr. 26, 2015 05:00 AM EDT Reads: 2,405
Temasys has announced senior management additions to its team. Joining are David Holloway as Vice President of Commercial and Nadine Yap as Vice President of Product. Over the past 12 months Temasys has doubled in size as it adds new customers and expands the development of its Skylink platform. Skylink leads the charge to move WebRTC, traditionally seen as a desktop, browser based technology, to become a ubiquitous web communications technology on web and mobile, as well as Internet of Things compatible devices.
Apr. 26, 2015 04:45 AM EDT Reads: 2,334
SYS-CON Events announced today that CommVault has been named “Bronze Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY, and the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. A singular vision – a belief in a better way to address current and future data management needs – guides CommVault in the development of Singular Information Management® solutions for high-performance data protection, universal availability and sim...
Apr. 26, 2015 04:45 AM EDT Reads: 2,068
SYS-CON Events announced today that SafeLogic has been named “Bag Sponsor” of SYS-CON's 16th International Cloud Expo® New York, which will take place June 9-11, 2015, at the Javits Center in New York City, NY. SafeLogic provides security products for applications in mobile and server/appliance environments. SafeLogic’s flagship product CryptoComply is a FIPS 140-2 validated cryptographic engine designed to secure data on servers, workstations, appliances, mobile devices, and in the Cloud.
Apr. 26, 2015 04:30 AM EDT Reads: 2,125
SYS-CON Events announced today that StorPool Storage will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. StorPool is distributed storage software that allows service providers, enterprises and other cloud builders to run data storage on standard x86 servers, instead of using expensive and inefficient storage arrays (SAN).
Apr. 26, 2015 04:00 AM EDT Reads: 2,249
GENBAND has announced that SageNet is leveraging the Nuvia platform to deliver Unified Communications as a Service (UCaaS) to its large base of retail and enterprise customers. Nuvia’s cloud-based solution provides SageNet’s customers with a full suite of business communications and collaboration tools. Two large national SageNet retail customers have recently signed up to deploy the Nuvia platform and the company will continue to sell the service to new and existing customers. Nuvia’s capabilities include HD voice, video, multimedia messaging, mobility, conferencing, Web collaboration, deskt...
Apr. 26, 2015 03:30 AM EDT Reads: 1,923
Sonus Networks introduced the Sonus WebRTC Services Solution, a virtualized Web Real-Time Communications (WebRTC) offer, purpose-built for the Cloud. The WebRTC Services Solution provides signaling from WebRTC-to-WebRTC applications and interworking from WebRTC-to-Session Initiation Protocol (SIP), delivering advanced real-time communications capabilities on mobile applications and on websites, which are accessible via a browser.
Apr. 26, 2015 02:45 AM EDT Reads: 2,004
SYS-CON Events announced today that Site24x7, the cloud infrastructure monitoring service, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Site24x7 is a cloud infrastructure monitoring service that helps monitor the uptime and performance of websites, online applications, servers, mobile websites and custom APIs. The monitoring is done from 50+ locations across the world and from various wireless carriers, thus providing a global perspective of the end-user experience. Site24x7 supports monitoring H...
Apr. 26, 2015 02:30 AM EDT Reads: 2,091
SYS-CON Events announced today that Intelligent Systems Services will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Established in 1994, Intelligent Systems Services Inc. is located near Washington, DC, with representatives and partners nationwide. ISS’s well-established track record is based on the continuous pursuit of excellence in designing, implementing and supporting nationwide clients’ mission-critical systems. ISS has completed many successful projects in Healthcare, Commercial, Manufacturing, ...
Apr. 26, 2015 02:15 AM EDT Reads: 2,819
SYS-CON Events announced today that B2Cloud, a provider of enterprise resource planning software, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. B2cloud develops the software you need. They have the ideal tools to help you work with your clients. B2Cloud’s main solutions include AGIS – ERP, CLOHC, AGIS – Invoice, and IZUM
Apr. 26, 2015 02:00 AM EDT Reads: 3,587
“With easy-to-use SDKs for Atmel’s platforms, IoT developers can now reap the benefits of realtime communication, and bypass the security pitfalls and configuration complexities that put IoT deployments at risk,” said Todd Greene, founder & CEO of PubNub. PubNub will team with Atmel at CES 2015 to launch full SDK support for Atmel’s MCU, MPU, and Wireless SoC platforms. Atmel developers now have access to PubNub’s secure Publish/Subscribe messaging with guaranteed ¼ second latencies across PubNub’s 14 global points-of-presence. PubNub delivers secure communication through firewalls, proxy ser...
Apr. 26, 2015 02:00 AM EDT Reads: 3,883
SYS-CON Events announced today that Tufin, the market-leading provider of Security Policy Orchestration Solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. As the market leader of Security Policy Orchestration, Tufin automates and accelerates network configuration changes while maintaining security and compliance. Tufin's award-winning Orchestration Suite™ gives IT organizations the power and agility to enforce security policy across complex, multi-vendor enterprise networks. With more than 1...
Apr. 26, 2015 01:45 AM EDT Reads: 3,625
VoxImplant has announced full WebRTC support in the newest versions of its Android SDK and iOS SDK. The updated SDKs, which enable audio and video calls on mobile devices, are now compatible with the WebRTC standard to allow any mobile app to communicate with WebRTC-enabled browsers, including Google Chrome, Mozilla Firefox, Opera, and, when available, Microsoft Spartan. The WebRTC-updated SDKs represent VoxImplant's continued leadership in simplifying the development of real-time communications (RTC) services for app developers. VoxImplant (built by Zingaya, the real-time communication servi...
Apr. 26, 2015 01:45 AM EDT Reads: 2,214
SYS-CON Events announced today that Cloudian, Inc., the leading provider of hybrid cloud storage solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Cloudian, Inc., is a Foster City, California - based software company specializing in cloud storage software. The main product is Cloudian, an Amazon S3-compliant cloud object storage platform, the bedrock of cloud computing systems, that enables cloud service providers and enterprises to build reliable, affordable and scalable cloud storage solu...
Apr. 26, 2015 01:00 AM EDT Reads: 2,756
SYS-CON Events announced today that Gridstore™, the leader in hyper-converged infrastructure purpose-built to optimize Microsoft workloads, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Gridstore™ is the leader in hyper-converged infrastructure purpose-built for Microsoft workloads and designed to accelerate applications in virtualized environments. Gridstore’s hyper-converged infrastructure is the industry’s first all flash version of HyperConverged Appliances that include both compute and storag...
Apr. 26, 2015 12:45 AM EDT Reads: 4,665
SYS-CON Events announced today that IDenticard will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. IDenticard™ is the security division of Brady Corp (NYSE: BRC), a $1.5 billion manufacturer of identification products. We have small-company values with the strength and stability of a major corporation. IDenticard offers local sales, support and service to our customers across the United States and Canada. Our partner network encompasses some 300 of the world's leading systems integrators and security s...
Apr. 26, 2015 12:00 AM EDT Reads: 5,277
SYS-CON Events announced today the IoT Bootcamp – Jumpstart Your IoT Strategy, being held June 9–10, 2015, in conjunction with 16th Cloud Expo and Internet of @ThingsExpo at the Javits Center in New York City. This is your chance to jumpstart your IoT strategy. Combined with real-world scenarios and use cases, the IoT Bootcamp is not just based on presentations but includes hands-on demos and walkthroughs. We will introduce you to a variety of Do-It-Yourself IoT platforms including Arduino, Raspberry Pi, BeagleBone, Spark and Intel Edison. You will also get an overview of cloud technologies s...
Apr. 25, 2015 07:15 PM EDT Reads: 3,039
“In the past year we've seen a lot of stabilization of WebRTC. You can now use it in production with a far greater degree of certainty. A lot of the real developments in the past year have been in things like the data channel, which will enable a whole new type of application," explained Peter Dunkley, Technical Director at Acision, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
Apr. 25, 2015 04:00 PM EDT Reads: 4,492
The best mobile applications are augmented by dedicated servers, the Internet and Cloud services. Mobile developers should focus on one thing: writing the next socially disruptive viral app. Thanks to the cloud, they can focus on the overall solution, not the underlying plumbing. From iOS to Android and Windows, developers can leverage cloud services to create a common cross-platform backend to persist user settings, app data, broadcast notifications, run jobs, etc. This session provides a high level technical overview of many cloud services available to mobile app developers, includi...
Apr. 25, 2015 04:00 PM EDT Reads: 1,429