logo
down
shadow

Creating a Drop Down Menu Bar in Java GUI


Creating a Drop Down Menu Bar in Java GUI

By : hoangph
Date : November 22 2020, 03:01 PM
To fix this issue There is no any need of adding JMenuBar object to JPanel because it is only linked with the JFrame.
You need to pass the JMenuBar object to JFrame method setJMenuBar() in order to set the menu bar in the window.
code :
    JMenuBar menuBar = new JMenuBar();
    JMenuItem saveItem, saveAllItem;

    // Menu
    JMenu fileMenu = new JMenu("File");

    // Menu Item (Drop down menus)
    saveItem = new JMenuItem("Save");
    saveAllItem = new JMenuItem("Save All");

    // Adding menu items to menu
    fileMenu.add(saveItem);
    fileMenu.add(saveAllItem);

    // adding menu to menu bar
    menuBar.add(fileMenu);

    // setting menubar at top of the window.

    // if you create a object of JFrame in class then code to set JMenuBar to JFrame will be:
    // jframe.setJMenuBar(menuBar);
    // if class is extending JFrame then it will be like this:
    setJMenuBar(menuBar);


Share : facebook icon twitter icon
Creating Drop Down Menu on click CSS

Creating Drop Down Menu on click CSS


By : Tibyan Ralibi
Date : March 29 2020, 07:55 AM
I wish this helpful for you CSS does not have a click handler. For this reason it is impossible to do with standard CSS. You could use something called the checkbox hack, but in my humble opinion, it's a bit clunky and would be awkward to work with inside a navigation menu like your use-case requires. For this reason I would suggest jQuery or Javascript... Here is a rather simple solution using jQuery.
Basically, we hide the sub-nav from the start using display: none; Then, using jQuery, when ".parent" is clicked we toggle a class ".visible" to the sub-nav element (the nested UL) with display: block; which makes it appear. When clicked again, it disappears as the class is removed.
code :
$(document).ready(function() {
  $('.parent').click(function() {
    $('.sub-nav').toggleClass('visible');
  });
});
#nav ul.sub-nav {
  display: none;
}

#nav ul.visible {
  display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="nav">
  <li>Home</li>
  <li class="parent">About
    <ul class="sub-nav">
      <li>Johnny</li>
      <li>Julie</li>
      <li>Jamie</li>
    </ul>
  </li>
  <li>Contact</li>
</ul>
Creating A Drop-down Menu

Creating A Drop-down Menu


By : TheReuss
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Check this fiddle out
I have used the HTML you posted and added a submenu to "Operations" list item. When you are creating a simple drop-down on hover, make the main menu items position: relavtive. Make the submenu items ul absolute position and position properties like top, left, right and bottom to position the submenu items where you want to display when it is hovered and make the subemnu items ul hidden by using display:none. Now on hover you can make the the sub-menu items ul visible using display: block.
code :
<div class="nav-wrapper">
    <div class="nav">
        <div class="pilot-main-login">
            <img src="http://lorempixel.com/50/50" />
        </div>
        <nav>
            <ul>
                <li>
                    <a href="index.php">Home</a>
                </li><li>
                    <a href="#">About</a>
                </li><li>
                    <a href="#">Operations</a>
                <ul>
                    <li>Sub menu 1</li>
                    <li>Sub menu 2</li>
                    <li>Sub menu 3</li>
                </ul>
                </li><li>
                    <a href="#">Pilot Application</a>
                </li><li>
                    <a href="#">VX Tracker</a>
                </li><li>
                    <a href="#">Contact Us</a>
                </li>
            </ul>
        </nav>
    </div>
</div>
.pilot-main-login{
    float:left;
}

.nav-wrapper{
    width:100%;
    height: 55px;
    background-color: #E20000;
    -webkit-box-shadow: 0px 0px 8px 2px #292827;
    -moz-box-shadow: 0px 0px 8px 2px #292827;
    box-shadow: 0px 0px 8px 2px #292827;
}

.nav{
    width: 960px;
    margin-left: auto;
    margin-right: auto;
    font-size: 16px;
    font-family: 'Ubuntu', sans-serif;
}

nav{
    float:left;
}

.nav ul{
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.nav li{
    line-height: 55px;
    text-align: center;
    display: inline-block;
    position:relative;
}

.nav li a{
    color: #FFF;
    display: block;
    text-decoration: none;
}

.nav  a:hover{
    background-color: #D40000;
}

.nav a{
    padding-left: 20px;
    padding-right: 20px;
}
// Styles for the sub menu item
.nav li > ul{
    display:none;
    position:absolute;
    top:100%;
    padding:0;
    background-color:yellow;
}
// To display submenu items on hover
.nav li:hover > ul{
    display:block;
}
<li><a href="#">Operations</a>
    <ul class="sub-menu">
        <li>Sub menu 1</li>
        <li>Sub menu 2</li>
        <li><a>Sub menu 3</a>
            <ul class="sub-sub-menu">
               <li>Sub sub menu 1</li>
               <li>Sub sub menu 2</li>
            </ul
        </li>
    </ul>
</li>
Creating a drop down menu

Creating a drop down menu


By : AMAL RAJ
Date : March 29 2020, 07:55 AM
I hope this helps you . If I understand it right, you want a drop down to occur when you hover over the text of the drop-down.
code :
<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
    background-color: #4CAF50;
    color: white;
    padding: 16px;
    font-size: 16px;
    border: none;
    cursor: pointer;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown:hover .dropbtn {
    background-color: #3e8e41;
}
</style>
</head>
<body>

    <h2>Dropdown Menu</h2>
    <p>Move the mouse over the button to open the dropdown menu.</p>

    <div class="dropdown">
        <button class="dropbtn">My Links</button>
        <div class="dropdown-content">
            <a href="#">Women</a>
            <a href="#">Men</a>
            <a href="#">Children</a>
        </div>
    </div>

</body>
</html>
Problem creating full width drop down menu that appears when we hover over menu item (using jQuery)

Problem creating full width drop down menu that appears when we hover over menu item (using jQuery)


By : Auguste Baudin
Date : March 29 2020, 07:55 AM
To fix this issue One way to handle it is to position the drop menus absolutely, so that you don't mouse out of the big-top-menu so the dropdown doesn't disappear.
Here's your code in a snippet with a little css change of
code :
position: absolute;
top: 50px;
$(document).ready(function(){  
$("#hover-industries").hover(function(){
        $("#drop-industries").css("display", "flex");
        }, function(){
          $("#drop-industries").hide();
    });
});

$(document).ready(function(){   
$("#hover-services").hover(function(){
        $("#drop-services").css("display", "flex");
                }, function() { 
                    $("#drop-services").css("display", "none");
        }); 

});
        body{
            background-color: aqua;
        }      
        #big-top-menu{
            display: flex;
            justify-content: space-around;
            background-color: antiquewhite;
        }
        #big-top-menu h3{
            height: 100%;
        }
        #drop-industries{
            display: none;
            position: absolute;
            top: 50px;
            background-color: white;
            flex-direction: column;
        }
        #drop-services{
            display: none;
            position: absolute;
            top: 50px;
            background-color: white;
            flex-direction: column;
        }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<div id="menu-and-drop">
   <div id="big-top-menu">
      <div id="hover-industries">
         <h3 id="industries-title"><a href="#">Industries</a></h3>
         <div id="drop-industries" class="one-drop">
            <a href="#">Automotive Industry</a>
            <a href="#">Biopharmaceuticals</a>
            <a href="#">Consumer Products</a>
            <a href="#">Education</a>
            <a href="#">Energy and Environment</a>
            <a href="#">Engineering Products <br>and Infrastructure</a>
         </div>
      </div>

      <div id="hover-services">
         <h3 id="services-title"><a href="#">Services</a></h3>
         <div id="drop-services" class="one-drop">
            <a href="#">Analytics</a>
            <a href="#">Corporate Finance</a>
            <a href="#">Customer Strategy</a>
            <a href="#">Information Technology</a>
            <a href="#">Operators</a>
            <a href="#">Performance Enhancement</a>
         </div>
      </div>
   </div>
</div>
Creating sub-menu for a child for a single drop down menu

Creating sub-menu for a child for a single drop down menu


By : Yentledo
Date : March 29 2020, 07:55 AM
wish helps you I need a single drop down menu that is displayed only on hover. From the drop down menu list, I need a further list on hover on one of the child items. , extraNav submenu must be inside of parent list item:
Related Posts Related Posts :
  • Interrupt CompletableFuture with default value
  • Eclipse - Choosing servers in "Run on server" vs setting "Target Runtime"
  • Spring JPA doesn't validate bean on update
  • How is takeWhile different from filter?
  • Spring Scheduled Cron jobs firing at wrong time
  • JFrame window resizing on every compile. Different results every time
  • Kotlin unresolved reference :add after converting from Java code
  • How to use Neo4j APOC method " apoc.export.csv.query(query,file,config)" in Java program
  • Regex to include all spanish characters and number
  • Parsing and Mapping a JSON Object with Dynamic Properties
  • Which approach to building domain objects in Spring MVC is more correct?
  • Java Long Min and Max not exact as mentioned in docs
  • Selenium opens new tab after SendKeys
  • How to sort a large array of ints?
  • FitNessse Test can not find Fixture
  • Including Signed Libraries in Executable JAR with Maven
  • If and Else statement run on second iteration of while loop
  • Change class of disabled tab on change of dropdown value
  • Junit5 @ParameterizedTest How to pass array as one of parameter
  • Text message not being sent to a list of numbers but is sent when just one number is specified
  • Spring mapped servlet not called in jetty-maven-plugin
  • How to pace the consumption of a sqs queue using spring integration
  • Autowiring Not getting disabled using xml configuration
  • Maze solve and shortest path with Java BFS
  • Spinner updating only on user actions
  • Why are Java rules for protected access such as they are?
  • Modify parameter of method by value in annotation aspectJ
  • How to send sensitive data to a Liferay portlet from outside the Liferay portal
  • Does a server connection stay open if created inside a method?
  • JAR manifest Class-Path, use folder instead of jar
  • How to do a bulk update in Firestore
  • ItemArray.checklist.add() not appending string to ArrayList
  • How to move something on screen without other picture staying there
  • SpringBoot : No matching bean found exception
  • Implementing the Clonable interface, but don't have to override the clone() method
  • how can i get this code to choose a random word once from each array to print a sentence?
  • Static class to get connections from connection pool
  • Unable to start Chrome browser with user profile in Selenium
  • How to pass a object to be created as a parameter for a method in Java?
  • How to retry with hystrix
  • Loading key to KeyStore fails on Android Oreo
  • Spring+Velocity unsuccessful attempts to save object
  • Private constructor in Kotlin
  • Jetty:run fails with NoSuchMethodError with Spring 5
  • Cannot upload my Web Applicartion in Jboss7 EAP7 EAP
  • How to load a certificate from "Credential storage"?
  • Call Genexus procedure stub in Java environment
  • JavaFX clipping produces a 'lottery scratch ticket'-Effect
  • Using DateTimeFormatter on january first cause an invalid year value
  • Get all the output from Watson conversation using java
  • Java unable to open main class and jar file
  • How to override @override method from activity into another class
  • Adding Runtime VM parameters to intellij for Java 9
  • Java IBM MQ Client connected but not getting messages from queue
  • Questions of Tomcat SSL configuration
  • Stale JNLP files for <extension> (since Java 9?)
  • Properly set (system) properties in JUnit 5
  • Spring MVC Model within POST Method is empty
  • VSTS buildagent: Java 9
  • java.lang.NumberFormatException: For input string: "id" for Hibernate
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org