2012-11-25 49 views
8

मैं नेटबीन्स का उपयोग कर रहा हूं और मैं जावा डेस्कटॉप एप्लिकेशन विकसित करना चाहता हूं। आवेदन किसी भी तरह की वेबसाइट जैसा होना चाहिए, मेरा मतलब है कि मैं अपने जावा डेस्कटॉप एप्लिकेशन में कुछ मेनू रखना चाहता हूं जो उन मेनू में से प्रत्येक पर क्लिक करके मुझे अलग-अलग पृष्ठों के साथ कुछ अलग-अलग पृष्ठों तक पहुंचने में सक्षम होना चाहिए (जैसे मुख्य मेनू, रिपोर्ट-मेनू ...।)। किसी भी विचार की अत्यधिक सराहना की जाएगी।जावा डेस्कटॉप एप्लिकेशन में मेनू (वेबसाइट स्टाइल नेविगेशन लिंक) कैसे हैं

उत्तर

5

यहां JavaFX आधारित नमूना है, जो hyperlinks के सेट पर आधारित विभिन्न सामग्री आइटमों के आधार पर मेनू उत्पन्न करता है। यह बहुत ही समान है कि वेब पेज कितने काम करते हैं। नमूना css के माध्यम से एक वेब पेज के समान स्टाइल किया गया है।

नमूना जावा कोड में दृश्य सामग्री बनाता है, लेकिन यदि आप चाहें तो SceneBuilder टूल द्वारा उत्पन्न fxml में सामग्री आइटम को परिभाषित कर सकते हैं।

जावाएफएक्स में पारंपरिक एप्लिकेशन menu bars भी है (इस नमूने में प्रदर्शित नहीं किया गया है)।

नमूना कार्यक्रम उत्पादन, कुछ अलग लिंक के साथ क्लिक किया:

sugar coffee

नमूना कोड:

import javafx.application.Application; 
import javafx.scene.*; 
import javafx.scene.control.*; 
import javafx.scene.image.Image; 
import javafx.scene.image.ImageView; 
import javafx.scene.layout.*; 
import javafx.stage.Stage; 

/** 
* Displays content panes activated by a hyper-link based navigation bar 
*/ 
public class HyperlinkedNavMenu extends Application { 
    private LinkContent[] linkContent; 

    private final StackPane content = new StackPane(); 

    public static void main(String[] args) { 
     launch(args); 
    } 

    @Override 
    public void start(Stage stage) { 
     linkContent = createLinkContent(); 

     content.setPrefWidth(200); 
     HBox.setHgrow(content, Priority.ALWAYS); 

     stage.setTitle("Capello Pazzo"); 
     stage.setScene(new Scene(createLayout())); 
     stage.show(); 
    } 

    private Pane createLayout() { 
     HBox layout = new HBox(
       10, 
       createNavBar(), 
       content 
     ); 

     layout.getStylesheets().add(
       getClass().getResource("nav.css").toExternalForm() 
     ); 

     return layout; 
    } 

    private VBox createNavBar() { 
     VBox nav = new VBox(); 
     nav.setMinWidth(100); 
     nav.getStyleClass().add("navbar"); 

     for (int i = 0; i < linkContent.length; i++) { 
      Hyperlink link = createLink(
        linkContent[i].linkText, 
        createContentNode(linkContent[i]) 
      ); 
      nav.getChildren().add(link); 
      if (i == 0) { 
       link.fire(); 
      } 
     } 

     return nav; 
    } 

    private Node createContentNode(LinkContent linkContent) { 
     Label label = new Label(linkContent.contentText); 
     label.setWrapText(true); 

     VBox contentNode = new VBox(
       10, 
       new ImageView(linkContent.image), 
       label 
     ); 
     contentNode.getStyleClass().add("contentnode"); 

     return contentNode; 
    } 

    private Hyperlink createLink(final String linkText, final Node contentNode) { 
     Hyperlink link = new Hyperlink(linkText); 
     link.setOnAction(t -> content.getChildren().setAll(
       contentNode 
     )); 

     return link; 
    } 

    private static class LinkContent { 
     final String linkText, contentText; 
     final Image image; 

     LinkContent(String linkText, String contentText, String imageLoc) { 
      this.linkText = linkText; 
      this.contentText = contentText; 
      this.image = new Image(imageLoc); 
     } 
    } 

    // icon license:  http://creativecommons.org/licenses/by-nc-nd/3.0/ 
    // icon attribution: http://www.iconarchive.com/artist/archigraphs.html 
    private LinkContent[] createLinkContent() { 
     return new LinkContent[] { 
       new LinkContent(
         "Lorem", 
         "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", 
         "http://icons.iconarchive.com/icons/archigraphs/tea-party/128/Sugar-Cubes-icon.png" 
       ), 
       new LinkContent(
         "Vestibulum", 
         "Vestibulum a dui et massa laoreet vehicula.", 
         "http://icons.iconarchive.com/icons/archigraphs/tea-party/128/Tea-Cake-icon.png" 
       ), 
       new LinkContent(
         "Donec", 
         "Donec sed euismod risus.", 
         "http://icons.iconarchive.com/icons/archigraphs/tea-party/128/Tea-Cup-icon.png" 
       ), 
       new LinkContent(
         "Duis", 
         "Duis semper porttitor leo ac posuere.", 
         "http://icons.iconarchive.com/icons/archigraphs/tea-party/128/Tea-Pot-icon.png" 
       ) 
     }; 
    } 
} 

नमूना सीएसएस:

/** file: nav.css 
* place in same directory as HyperlinkedNavMenu.java and have your build system copy it 
* to the same location as HyperlinkedNavMenu.java.class */ 

.root { 
    -fx-background-image: url("http://images.all-free-download.com/images/graphiclarge/linen_fabric_background_04_hd_picture_169825.jpg"); 
    -fx-padding: 15; 
    -fx-font-size: 15; 
} 

.navbar { 
    -fx-background-color: burlywood, peachpuff; 
    -fx-background-radius: 10, 10; 
    -fx-background-insets: 0, 2; 
    -fx-font-style: italic; 
    -fx-padding: 10 15 15 10; 
} 

.contentnode { 
    -fx-background-color: aliceblue; 
    -fx-padding: 15 20 20 15; 
    -fx-effect: dropshadow(gaussian, slategrey, 10, 0, 5, 5); 
} 
0

आप एक IDE Netbeans है जैसे कि यह manu bar, manu और की सुविधा देता है प्रयोग कर रहे हैं manu item आप खींचें और JFrame से अधिक menu bar ड्रॉप और इसे करने के लिए manus और मेनू आइटम जोड़ सकते हैं।

या

आप एक ही जगह में एकाधिक फ्रेम दिखाने के लिए करने के लिए कार्ड लेआउट का उपयोग कर सकते हैं।