Re: Drop-Down-Menu in JToolbar



On May 26, 9:13 pm, Thorsten Kiefer <thorstenkie...@xxxxxx> wrote:
...
...It's not possible to add JPopupMenu to JToolbar.

Which Java are you using?

Or perhaps I should ask, which JavaDocs are you
*failing* to use?

<sscce>
import javax.swing.*;

class ToolBarWithPopupMenu {

public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JFrame f = new JFrame();

JToolBar tb = new JToolBar();
JPopupMenu popup = new JPopupMenu();
tb.setComponentPopupMenu( popup );

for (int ii=0; ii<4; ii++) {
tb.add( new JButton("" + ii) );
popup.add( "" + ii);
}
f.add( tb );

f.pack();
f.setVisible(true);
}
};
java.awt.EventQueue.invokeLater(r);
}
}
</sscce>

--
Andrew T.
PhySci.org
.


Quantcast