Toolbar wie im Explorer? oder mozilla erstellen

Status
Nicht offen für weitere Antworten.
S

Stiefel

Gast
Ich bins schon wieder wies niemand wie man eine Toolbar erstellen kann das die so aussieht wie im Mozilla? Bzw das es professionell aussieht??
 

L-ectron-X

Gesperrter Benutzer
Die Frage ist etwas unglücklich gestellt, sie würde nur dumme Antworten und weitere Fragen provozieren.
Was genau ist dein Problem?
 
S

Stiefel

Gast
Mmh mist jetzt war ich doch zu voreilig an der Musterlösung kann man sehn wen nman sie übersetzt das es keine Abstänfe mehr gibt jetzt is allerdings meine Frage wie bekomm ich das hin ohne von JPANEL erben zu müssen??

Weis jemand wie ich die LAYOUTS genau definieren muss dmait der Abstand wie in dieser Lösung zu sehn ist verschwindet ohne halt von JPANEL erben zu müssen??


Code:
package components;

/*
 * ToolBarDemo.java requires the following addditional files:
 * images/Back24.gif
 * images/Forward24.gif
 * images/Up24.gif
 */

import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JTextField;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.SwingUtilities;

import java.net.URL;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ToolBarDemo2 extends JPanel
                          implements ActionListener {
    protected JTextArea textArea;
    protected String newline = "\n";
    static final private String PREVIOUS = "previous";
    static final private String UP = "up";
    static final private String NEXT = "next";
    static final private String SOMETHING_ELSE = "other";
    static final private String TEXT_ENTERED = "text";

    public ToolBarDemo2() {
        super(new BorderLayout());

        //Create the toolbar.
        JToolBar toolBar = new JToolBar("Still draggable");
        addButtons(toolBar);
        toolBar.setFloatable(false);
        toolBar.setRollover(true);

        //Create the text area used for output.  Request
        //enough space for 5 rows and 30 columns.
        textArea = new JTextArea(5, 30);
        textArea.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(textArea);

        //Lay out the main panel.
        setPreferredSize(new Dimension(450, 130));
        add(toolBar, BorderLayout.PAGE_START);
        add(scrollPane, BorderLayout.CENTER);
    }

    protected void addButtons(JToolBar toolBar) {
        JButton button = null;

        //first button
        button = makeNavigationButton("Back24", PREVIOUS,
                                      "Back to previous something-or-other",
                                      "Previous");
        toolBar.add(button);

        //second button
        button = makeNavigationButton("Up24", UP,
                                      "Up to something-or-other",
                                      "Up");
        toolBar.add(button);

        //third button
        button = makeNavigationButton("Forward24", NEXT,
                                      "Forward to something-or-other",
                                      "Next");
        toolBar.add(button);

        //separator
        toolBar.addSeparator();

        //fourth button
        button = new JButton("Another button");
        button.setActionCommand(SOMETHING_ELSE);
        button.setToolTipText("Something else");
        button.addActionListener(this);
        toolBar.add(button);

        //fifth component is NOT a button!
        JTextField textField = new JTextField("A text field");
        textField.setColumns(10);
        textField.addActionListener(this);
        textField.setActionCommand(TEXT_ENTERED);
        toolBar.add(textField);
    }

    protected JButton makeNavigationButton(String imageName,
                                           String actionCommand,
                                           String toolTipText,
                                           String altText) {
        //Look for the image.
        String imgLocation = "images/"
                             + imageName
                             + ".gif";
        URL imageURL = ToolBarDemo2.class.getResource(imgLocation);

        //Create and initialize the button.
        JButton button = new JButton();
        button.setActionCommand(actionCommand);
        button.setToolTipText(toolTipText);
        button.addActionListener(this);

        if (imageURL != null) {                      //image found
            button.setIcon(new ImageIcon(imageURL, altText));
        } else {                                     //no image found
            button.setText(altText);
            System.err.println("Resource not found: "
                               + imgLocation);
        }

        return button;
    }

    public void actionPerformed(ActionEvent e) {
        String cmd = e.getActionCommand();
        String description = null;

        // Handle each button.
        if (PREVIOUS.equals(cmd)) { //first button clicked
            description = "taken you to the previous <something>.";
        } else if (UP.equals(cmd)) { // second button clicked
            description = "taken you up one level to <something>.";
        } else if (NEXT.equals(cmd)) { // third button clicked
            description = "taken you to the next <something>.";
        } else if (SOMETHING_ELSE.equals(cmd)) { // fourth button clicked
            description = "done something else.";
        } else if (TEXT_ENTERED.equals(cmd)) { // text field
            JTextField tf = (JTextField)e.getSource();
            String text = tf.getText();
            tf.setText("");
            description = "done something with this text: "
                          + newline + "  \""
                          + text + "\"";
        }

        displayResult("If this were a real app, it would have "
                        + description);
    }

    protected void displayResult(String actionDescription) {
        textArea.append(actionDescription + newline);
        textArea.setCaretPosition(textArea.getDocument().getLength());
    }

    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event dispatch thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("ToolBarDemo2");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Add content to the window.
        frame.add(new ToolBarDemo2());

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
	//Schedule a job for the event dispatch thread:
        //creating and showing this application's GUI.
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                //Turn off metal's use of bold fonts
	        UIManager.put("swing.boldMetal", Boolean.FALSE);
	       	createAndShowGUI();
            }
        });
    }
}



Dieser Beitrag wurde von L-ectron-X am 29.07.2007 um 18:33 Uhr editiert.
Code-Tags gesetzt, Doppelposting entfernt.
 

Jonnsn

Bekanntes Mitglied
Code boxen benutzen und nicht immer alles doppelt posten?!
Code:
System.out.println("steigert nämlich die Übersicht enorm...");"
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
J Aufklappbares Panel in Toolbar AWT, Swing, JavaFX & SWT 6
J Suche nach einer horizontal aufklappbaren Toolbar AWT, Swing, JavaFX & SWT 1
E JavaFX MenuBar und ToolBar zu einem Bereich AWT, Swing, JavaFX & SWT 3
T JavaFX Toolbar resizable AWT, Swing, JavaFX & SWT 4
dzim Toolbar - Problem bei enable/disable von Buttons AWT, Swing, JavaFX & SWT 6
I Toolbar AWT, Swing, JavaFX & SWT 27
A AWT Java Toolbar AWT, Swing, JavaFX & SWT 6
P SWT Toolbar mit nur einer Schaltfläche und einem Textfeld AWT, Swing, JavaFX & SWT 2
B Applet Button oder Toolbar in einem Applet AWT, Swing, JavaFX & SWT 5
C Swing Toolbar zur Laufzeit austauschen AWT, Swing, JavaFX & SWT 5
padde479 Suche eine Komponente (->ToolBar) AWT, Swing, JavaFX & SWT 7
S SWT perspektive mit toolbar oder eventkomponente AWT, Swing, JavaFX & SWT 3
B Buttons in Toolbar einbinden AWT, Swing, JavaFX & SWT 6
S SWT ToolBar Buttons mit Text und Bild AWT, Swing, JavaFX & SWT 15
C Swing Andocken einer ToolBar verhindern AWT, Swing, JavaFX & SWT 3
S Dropdown-Menü wie auf der Eclipse-Toolbar AWT, Swing, JavaFX & SWT 7
G Verliere Referenz von Toolbar bei mehreren Fenster AWT, Swing, JavaFX & SWT 3
W SWING - Aktionen in Toolbar hinzufügen AWT, Swing, JavaFX & SWT 2
B Toolbar, Toolbar In Toolbar, alterna zu JToolbar AWT, Swing, JavaFX & SWT 3
G SWT Toolbar: Toolitem entfernen und wieder hinzufügen AWT, Swing, JavaFX & SWT 16
S ToolBar in GridbagLayout AWT, Swing, JavaFX & SWT 5
S Tooltip auf Toolbar-Icon AWT, Swing, JavaFX & SWT 6
G Toolbar AWT, Swing, JavaFX & SWT 5
B PNG-Icons in Toolbar einbinden AWT, Swing, JavaFX & SWT 3
G Abstand zwischen den Buttons in einer Toolbar AWT, Swing, JavaFX & SWT 3
masta // thomas Toolbar wie in MacOS? AWT, Swing, JavaFX & SWT 13
M Toolbar Layout AWT, Swing, JavaFX & SWT 7
K Desktop toolbar Problem AWT, Swing, JavaFX & SWT 2
G Toolbar hat zuviel zwischenraum AWT, Swing, JavaFX & SWT 2
B Toolbar und Java-Versionen AWT, Swing, JavaFX & SWT 6
W ToolBar und StandardButtons AWT, Swing, JavaFX & SWT 9
S toolbar - flowlayout problem AWT, Swing, JavaFX & SWT 5
S Toolbar in einem BorderLayout verschieben AWT, Swing, JavaFX & SWT 4
G Toolbar mit Toolbuttons AWT, Swing, JavaFX & SWT 7
J Separator zwischen den einzelnen Symbolen in der Toolbar AWT, Swing, JavaFX & SWT 4
javasdann Icon in Toolbar ändern. AWT, Swing, JavaFX & SWT 4
javasdann MDI Problem mit Toolbar und Statusleiste. AWT, Swing, JavaFX & SWT 2
J Drop-down menü in Toolbar Button AWT, Swing, JavaFX & SWT 8
K toolbar dynamisch erzeugen AWT, Swing, JavaFX & SWT 2
A Bestes Layout für die Toolbar AWT, Swing, JavaFX & SWT 7
L Swing: Toolbar-Problem AWT, Swing, JavaFX & SWT 3
B Zugriff von Toolbar auf zugehörigen Frame AWT, Swing, JavaFX & SWT 6
S SWT Drag´n´Drop vom Desktop/Explorer AWT, Swing, JavaFX & SWT 7
P JTree - Explorer mit nur eingeschränkter Anzeige AWT, Swing, JavaFX & SWT 17
H explorer in java - datein kopieren AWT, Swing, JavaFX & SWT 5
M Problem mit eigenem Menu Explorer AWT, Swing, JavaFX & SWT 6
B Dropdown-Menü im Explorer AWT, Swing, JavaFX & SWT 4
C Explorer Bar für Java? AWT, Swing, JavaFX & SWT 11
S Swing Element für Explorer-Fenster darstellung AWT, Swing, JavaFX & SWT 13
C File Explorer simulieren AWT, Swing, JavaFX & SWT 6
K Foto Explorer AWT, Swing, JavaFX & SWT 9
H Wie bastelt man eine Baumstruktur wie im Windows-Explorer? AWT, Swing, JavaFX & SWT 5
L windows explorer AWT, Swing, JavaFX & SWT 4
P XML-File in Java-App darstellen - wie im Internet Explorer AWT, Swing, JavaFX & SWT 2

Ähnliche Java Themen

Neue Themen


Oben