Creating Hidden Buttons with Swing

Creating Hidden Buttons with Swing

Using Swing, you can easily create hidden buttons similar to the Back button used in Netscape Communicator 4. Hidden buttons look like normal graphic elements on the screen until you float over them with the mouse. This code was tested using JDK1.1.6 and Swing 1.0.3 under Win95:

 import java.awt.*;import java.awt.event.*;import com.sun.java.swing.*;public class SwingHiddenButton01 extends JFrame {	public static void main(String args[]) {		SwingHiddenButton01 demoFrame = 				new SwingHiddenButton01();	}//end main()	//-----------------------------------------------------//  	SwingHiddenButton01() {//constructor		setTitle("Hidden Buttons");		getContentPane().setLayout(new FlowLayout());		//Create two hidden buttons with no action listeners		JButton myJButton = new JButton("myButton");		myJButton.setBorderPainted(false);		myJButton.addMouseListener(new MyMouseListener());		getContentPane().add(myJButton);    		JButton urJButton = new JButton("urButton");		urJButton.setBorderPainted(false);		urJButton.addMouseListener(new MyMouseListener());		getContentPane().add(urJButton); 		//Set to windows look & feel    		String plafClassName = 			 "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";		try{			UIManager.setLookAndFeel(plafClassName);		}catch(Exception ex){System.out.println(ex);}		SwingUtilities.updateComponentTreeUI(this);		setSize(300,100);		setVisible(true);    		// Inner class WindowAdapter to terminate the		// program when the JFrame is closed.		addWindowListener(new WindowAdapter() {			public void windowClosing(WindowEvent e) {				System.exit(0);}});//end WindowListener    	}//end constructor	//=====================================================//	//Inner mouse listener class to show and hide buttons 	class MyMouseListener extends MouseAdapter{		public void mouseEntered(MouseEvent e){			//Display border on the button			((JButton)e.getSource()).setBorderPainted(true);		}//end mouseEntered()		public void mouseExited(MouseEvent e){			//Hide border on the button			((JButton)e.getSource()).setBorderPainted(false);		}//end mouseEntered()	}//end inner class myMouseListener     }//end class SwingHiddenButton01
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

©2023 Copyright DevX - All Rights Reserved. Registration or use of this site constitutes acceptance of our Terms of Service and Privacy Policy.

Sitemap