Platzierung eines JToolBar



  • ich will einfach per Event Handling eine Toolbar ersetellen

    das porblem wenn ich den HTML_toolbar in actionPerformed erstelle lässt sich gar nicht zeigen

    ic habe folgend Methoden verwendet
    setSize()
    setBounds()
    setPreferredize()
    setLocation()

    bei alle Methoden ist immer dasselbe woran könnte es liegen
    wie kann man das problem lösen ???

    Danke

    code
    *****
    import javax.swing.;
    import java.awt.
    ;
    import java.awt.event.*;

    public class StartEdit extends JFrame implements ActionListener
    {
    ......
    private Container contentPane;
    public Dimension dim;
    private JToolBar HTML_toolBar, JSCRIPT_toolBar;

    public StartEdit(String selectedLanguage)
    {
    super("PowerEdit");
    ....

    contentPane=this.getContentPane();
    contentPane.setLayout(null);
    Dimension(Toolkit.getDefaultToolkit().getScreenSize());
    this.setBounds(0,0,new Double(dim.getWidth()).intValue(),new
    Double(dim.getHeight()).intValue());
    langCode=new LangCode(getSelectedLanguage());
    .....
    ......

    toolBar=new JToolBar();
    toolBar.setBorder(BorderFactory.createEtchedBorder());
    toolBar.setBorderPainted(true);
    contentPane.add(toolBar);

    HTML_toolBar = new JToolBar();
    JSCRIPT_toolBar = new JToolBar();

    }
    //------------------------------------------------------------------------------
    public void actionPerformed(ActionEvent event)
    {
    if(event.getSource().equals(mTools_HTML)){
    contentPane.remove(JSCRIPT_toolBar);
    HTML_toolBar = new JToolBar();
    HTML_toolBar.setBorder(BorderFactory.createEtchedBorder());
    HTML_toolBar.setBorderPainted(true);
    HTML_toolBar.setPreferredSize(new Dimension(new
    Double(dim.getWidth()).intValue(),30));
    HTML_toolBar.setBackground(Color.red);
    contentPane.add(HTML_toolBar);
    }
    if(event.getSource().equals(mTools_JSCRIPT)){
    contentPane.remove(HTML_toolBar);
    contentPane.remove(XML_toolBar);
    contentPane.remove(CPLUS_toolBar);
    contentPane.remove(JAVA_toolBar);
    JSCRIPT_toolBar = new JToolBar();
    JSCRIPT_toolBar.setBorder(BorderFactory.createEtchedBorder());
    JSCRIPT_toolBar.setBorderPainted(true);
    JSCRIPT_toolBar.setBounds(0,30,new Double(dim.getWidth()).intValue(),30);
    JSCRIPT_toolBar.setVisible(true);
    contentPane.add(JSCRIPT_toolBar);
    }
    }
    //------------------------------------------------------------------------------
    }



  • // Create a horizontal toolbar
        JToolBar toolbar = new JToolBar();
    
        // Create a vertical toolbar
        toolbar = new JToolBar(null, JToolBar.VERTICAL);
    
        // Get current orientation
        int orient = toolbar.getOrientation();
    
    The following code adds various buttons to the toolbar: 
        // Get icon
        ImageIcon icon = new ImageIcon("icon.gif");
    
        // Create an action with an icon
        Action action = new AbstractAction("Button Label", icon) {
            // This method is called when the button is pressed
            public void actionPerformed(ActionEvent evt) {
                // Perform action
            }
        };
    
        // Add a button to the toolbar; remove the label and margin before adding
        JButton c1 = new JButton(action);
        c1.setText(null);
        c1.setMargin(new Insets(0, 0, 0, 0));
        toolbar.add(c1);
    
        // Add a toggle button; remove the label and margin before adding
        JToggleButton c2 = new JToggleButton(action);
        c2.setText(null);
        c2.setMargin(new Insets(0, 0, 0, 0));
        toolbar.add(c2);
    
        // Add a combobox
        JComboBox c3 = new JComboBox(new String[]{"A", "B", "C"});
        c3.setPrototypeDisplayValue("XXXXXXXX"); // Set a desired width
        c3.setMaximumSize(c3.getMinimumSize());
        toolbar.add(c3);
    

    vielleicht kannst du hier das fehlende rauspicken.

    gruss devil667


Anmelden zum Antworten