JMenuBar Height
Dear All,
is there any way to increase the height of JMenuBar..? and Here i am using JFrame with JMenuBar
i tried setSize() API but its not happing..!
Thank you
Balasundaram L
1. Why do you want to do this?
2. It may be possible using setPreferredSize(...) on the JMenuBar or any of its contained JMenus. Try that and if it doesn't help, post a [_SSCCE_|http://mindprod.com/jgloss/sscce.html] that clearly demonstrates your problem.
Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
db
Similar Messages
-
Java.awt.Image getWidth() and getHeight() not working!
Right- this is want I want to do.
I have a background image which is added as a background image to a third party API class which extends Java.awt.Container. Such container is then added to the Content Pane of MyClass (which extends JFrame)
I want to read the width and height of the image and resize MyClass accordingly.
Problem is calling theImage.getWidth(MyClass.this) or theImage.getWidth(theThirdPartyAPIContainer) always return -1 and -1 denoting that no information is available.
What do I need to do to obtain the height and width?Post here, cos don't know your email.
Anyway
- Can't use setPreferredSize because the Conatiner which is added to the ContentPane is a Awt Component not a Swing JComponent!
- Also, the background is added AFTER the this.pack()and this.show().
-I figured out that I could access Insets.top, Insets.left, Insets.right, Insets.bottom.
I have basically the following
|JMenuBar |
L____________________________________________|
| |
| |
| |
| Third Party Class extending java.awt.Container |
| containing an image of known size |
| |
L____________________________________________|
I am fine for the width I do
Insets frameInsets = this.getInsets();
width = image.getWidth() + frameInsets.left + frameInsets.right;
Height is the problem
After some Trial an error it LOOKS on Solaris as if the following is right-
height = image.getHeight()+frameInsets.top+ myJMenuBar.getSize()+getHeight+ myJMenuBar.getInsets().top + myJMenuBar.getInsets().bottom
I cannot comprehend whether this is just a coincidence or not as I don't know why frameInsets.bottom should in any case be excluded.
Here are the dimensions-
frameInsets.left = 6
frameInsets.right= 6
frameInsets.top =28
frameInsets.bottom = 6
JMenuBar height = 23
JMenuBar's Insets.top = 1
JMenuBar's Insets.bottom = 1
What should be the 'correct' calculations and does the Insets for the JMenuBar and the JFrame overlaps? -
JMenuBar set location and/or height
Hello,
I was just wondering if it is possible to place a JMenuBar at the bottom of a frame instead of at the top that it seems to goto by default. Also was wondering if it is possible to change the height of a JMenuBar. Any help would be great thanks. :)A menu bar contains one or more menus and has a customary, platform-dependent location ? usually along the top of a window
Perhaps you could create your own look and feel and perhaps you could use the Swing forum in future. -
Problems getting data from JMenuBar to JInternalFrame
I have modified an example to show my problem. I am trying to take text input from the menu bar and print it into a JTextArea. I don't know how to reference the data in my ActionListener.
The ActionListener is incomplete, but this is basically what I am trying to do:
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
* InternalFrameDemo.java is a 1.4 application that requires:
* MyInternalFrame.java
public class InternalFrameDemo extends JFrame
implements ActionListener {
JDesktopPane desktop;
JTextField memAddrBox;
JTextArea menuText;
JTextArea frame;
String textFieldString = " Input Text: ";
ActionListener al;
public InternalFrameDemo() {
super("InternalFrameDemo");
//Make the big window be indented 50 pixels from each edge
//of the screen.
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height - inset*2);
//Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
frame = createFrame(); //create first "window"
setContentPane(desktop);
setJMenuBar(createMenuBar());
//Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JLabel memAddrLabel = new JLabel(textFieldString);
memAddrLabel.setLabelFor(memAddrBox);
menuBar.add(memAddrLabel);
JTextField memAddrBox = new JTextField();
memAddrBox.addActionListener(this);
memAddrBox.setActionCommand("chMemAddr");
menuBar.add(memAddrBox);
return menuBar;
//React to menu selections.
public void actionPerformed(ActionEvent e) {
if ("chMemAddr".equals(e.getActionCommand()))
JMenuBar bar = getJMenuBar();
// JTextField memAddrBox = bar.getParent();
String memStartString = memAddrBox.getText();
update(memStartString);
public void update(String temp)
frame.setText(temp);
//Create a new internal frame.
protected JTextArea createFrame() {
JInternalFrame frame = new JInternalFrame("Memory",true,true,true,true);
frame.setSize(650, 500);
frame.setVisible(true);
frame.setLocation(200, 0);
desktop.add(frame);
JTextArea textArea = new JTextArea();
frame.getContentPane().add("Center", textArea);
textArea.setFont(new Font("SansSerif", Font.PLAIN, 12));
textArea.setVisible(true);
textArea.setText("Initial Text");
return textArea;
//Quit the application.
protected void quit() {
System.exit(0);
public static void main(String[] args) {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
InternalFrameDemo frame = new InternalFrameDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Display the window.
frame.setVisible(true);
class MyInternalFrame extends JInternalFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;
public MyInternalFrame() {
super("Document #" + (++openFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
//...Create the GUI and put it in the window...
//...Then set the window size or call pack...
setSize(300,300);
//Set the window's location.
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
}I want to take the input from the "memAddrBox" and put it into the "frame" using the update() method. Probably a simple solution, but I have not found a similar problem in the Forums.I knew it had to be something simple, here is the fix I found:
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
* InternalFrameDemo.java is a 1.4 application that requires:
* MyInternalFrame.java
public class InternalFrameDemo extends JFrame
implements ActionListener {
JDesktopPane desktop;
JTextField memAddrBox;
JTextArea menuText;
JTextArea frame;
String textFieldString = " Input Text: ";
ActionListener al;
public InternalFrameDemo() {
super("InternalFrameDemo");
//Make the big window be indented 50 pixels from each edge
//of the screen.
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height - inset*2);
//Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
frame = createFrame(); //create first "window"
setContentPane(desktop);
setJMenuBar(createMenuBar());
//Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JLabel memAddrLabel = new JLabel(textFieldString);
memAddrLabel.setLabelFor(memAddrBox);
menuBar.add(memAddrLabel);
JTextField memAddrBox = new JTextField();
memAddrBox.addActionListener(this);
memAddrBox.setActionCommand("chMemAddr");
menuBar.add(memAddrBox);
return menuBar;
//React to menu selections.
public void actionPerformed(ActionEvent e) {
if ("chMemAddr".equals(e.getActionCommand()))
JTextField textField =
(JTextField)e.getSource();
String memStartString = textField.getText();
update(memStartString);
public void update(String temp)
frame.setText(temp);
//Create a new internal frame.
protected JTextArea createFrame() {
JInternalFrame frame = new JInternalFrame("Memory",true,true,true,true);
frame.setSize(650, 500);
frame.setVisible(true);
frame.setLocation(200, 0);
desktop.add(frame);
JTextArea textArea = new JTextArea();
frame.getContentPane().add("Center", textArea);
textArea.setFont(new Font("SansSerif", Font.PLAIN, 12));
textArea.setVisible(true);
textArea.setText("Initial Text");
return textArea;
//Quit the application.
protected void quit() {
System.exit(0);
public static void main(String[] args) {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
InternalFrameDemo frame = new InternalFrameDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Display the window.
frame.setVisible(true);
class MyInternalFrame extends JInternalFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;
public MyInternalFrame() {
super("Document #" + (++openFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
//...Create the GUI and put it in the window...
//...Then set the window size or call pack...
setSize(300,300);
//Set the window's location.
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
}Note the e.getSource() change in the ActionListener. -
How to add a JMenubar and a JTable in a JFrame in a single application
Hi all,
I require an urgent help from you.I am a beginer in programming Swing.I want to add a menu,combobox,and a table in a single application.I did coding as below:
package com.BSS;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class newssa extends JFrame
public JMenuBar menuBar;
public JToolBar toolBar;
public JFrame frame;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JComboBox jComboBox1;
private JComboBox jComboBox2;
private JComboBox jComboBox3;
private JComboBox jComboBox4;
private JComboBox jComboBox5;
private JComboBox jComboBox6;
private JTable jTable1;
private JScrollPane jScrollPane1;
private JPanel contentPane;
public newssa()
super();
initializeComponent();
this.setVisible(true);
private void initializeComponent()
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jLabel4 = new JLabel();
jLabel5 = new JLabel();
jLabel6 = new JLabel();
jComboBox1 = new JComboBox();
jComboBox2 = new JComboBox();
jComboBox3 = new JComboBox();
jComboBox4 = new JComboBox();
jComboBox5 = new JComboBox();
jComboBox6 = new JComboBox();
frame=new JFrame();
//Included here
JMenuBar menuBar = new JMenuBar();
JMenu general = new JMenu("General");
menuBar.add(general);
JMenu actions =new JMenu("Actions");
menuBar.add(actions);
JMenu view=new JMenu("View");
menuBar.add(view);
JMenu Timescale=new JMenu("TimeScale");
menuBar.add(Timescale);
Timescale.add("Today CTRL+D");
Timescale.add("Current Week CTRL+W");
Timescale.add("Current Month CTRL+M");
Timescale.add("Current Quarter CTRL+Q");
Timescale.add("Current Year CTRL+Y");
Timescale.add("Custom TimeScale CTRL+U");
JMenu start=new JMenu("Start");
menuBar.add(start);
JMenu options=new JMenu("Options");
menuBar.add(options);
JMenu help=new JMenu("Help");
menuBar.add(help);
JFrame.setDefaultLookAndFeelDecorated(true);
frame.setJMenuBar(menuBar);
frame.pack();
frame.setVisible(true);
toolBar = new JToolBar("Formatting");
toolBar.addSeparator();
//Before this included new
String columnNames[] = { "ColorStatus", "Flash", "Service Order","Configuration","Configuration Description"};
// Create some data
String dataValues[][] =
{ "blue", "flash", "ORT001" },
{ "AVCONF", "av configuration with warrenty"}
// Create a new table instance
//jTable1 = new JTable( dataValues, columnNames );
jTable1 = new JTable(dataValues,columnNames);
jScrollPane1 = new JScrollPane(jTable1);
contentPane = (JPanel)this.getContentPane();
//scrollPane = new JScrollPane( table );
//topPanel.add( scrollPane, BorderLayout.CENTER );
// jLabel1
jLabel1.setText("Service Centers");
// jLabel2
jLabel2.setText("Service Areas");
// jLabel4
jLabel3.setText("Skills");
jLabel4.setText("Availablity Types");
// jLabel5
jLabel5.setText("From Date");
// jLabel6
jLabel6.setText("To");
// jComboBox1
jComboBox1.addItem("Coimbatore");
jComboBox1.addItem("Chennai");
jComboBox1.addItem("Mumbai");
jComboBox1.addItem("New Delhi");
jComboBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
jComboBox1_actionPerformed(e);
// jComboBox2
jComboBox2.addItem("North Zone");
jComboBox2.addItem("South Zone");
jComboBox2.addItem("Central Zone");
jComboBox2.addItem("Eastern Zone");
jComboBox2.addItem("Western Zone");
jComboBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
jComboBox2_actionPerformed(e);
// jComboBox3
jComboBox3.addItem("Microsoft Components");
jComboBox3.addItem("Java Technologies");
jComboBox3.addItem("ERP");
jComboBox3.addItem("Others");
jComboBox3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
jComboBox3_actionPerformed(e);
// jComboBox4
jComboBox4.addItem("One");
jComboBox4.addItem("Two");
jComboBox4.addItem("Three");
jComboBox4.addItem("Four");
jComboBox4.addItem("Five");
jComboBox4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
jComboBox4_actionPerformed(e);
// jComboBox5
jComboBox5.addItem("12/12/2004");
jComboBox5.addItem("13/12/2004");
jComboBox5.addItem("14/12/2004");
jComboBox5.setEditable(true);
jComboBox5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
jComboBox5_actionPerformed(e);
// jComboBox6
jComboBox6.addItem("12/11/2004");
jComboBox6.addItem("13/11/2004");
jComboBox6.addItem("14/11/2004");
jComboBox6.setEditable(true);
jComboBox6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
jComboBox6_actionPerformed(e);
// jTable1
jTable1.setModel(new DefaultTableModel(4, 4));
// jScrollPane1
jScrollPane1.setViewportView(jTable1);
// contentPane
contentPane.setLayout(null);
addComponent(contentPane, jLabel1, 2,29,84,18);
addComponent(contentPane, jLabel2, 201,33,76,18);
addComponent(contentPane, jLabel3, 384,32,59,18);
addComponent(contentPane, jLabel4, 2,77,85,18);
addComponent(contentPane, jLabel5, 197,79,84,18);
addComponent(contentPane, jLabel6, 384,80,60,18);
addComponent(contentPane, jComboBox1, 85,32,100,22);
addComponent(contentPane, jComboBox2, 276,32,100,22);
addComponent(contentPane, jComboBox3, 419,30,100,22);
addComponent(contentPane, jComboBox4, 88,76,100,22);
addComponent(contentPane, jComboBox5, 276,79,100,22);
addComponent(contentPane, jComboBox6, 421,78,100,22);
addComponent(contentPane, jScrollPane1, 33,158,504,170);
// newssa
this.setTitle("SSA Service Scheduler");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(560, 485));
/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height)
c.setBounds(x,y,width,height);
container.add(c);
// TODO: Add any appropriate code in the following Event Handling Methods
private void jComboBox1_actionPerformed(ActionEvent e)
int index = jComboBox1.getSelectedIndex();
switch(index)
case 0: System.out.println("Area Coimbatore Selected "); break;
case 1: System.out.println("Area Chennai selected"); break;
case 2: System.out.println("Mumbai being selected"); break;
case 3: System.out.println("New Delhi being selected"); break;
private void jComboBox2_actionPerformed(ActionEvent e)
int index = jComboBox2.getSelectedIndex();
switch(index)
case 0: System.out.println("North Zone Selcted "); break;
case 1: System.out.println("South Zone being selected"); break;
case 2: System.out.println("Central Zone being selected"); break;
case 3: System.out.println("Eastern Zone being selected"); break;
case 4: System.out.println("Western Zone being selected"); break;
private void jComboBox3_actionPerformed(ActionEvent e)
int index = jComboBox3.getSelectedIndex();
switch(index)
case 0: System.out.println("Microsoft Components being selected"); break;
case 1: System.out.println("Java Technologies being selected"); break;
case 2: System.out.println("ERP Tehnologies being selected"); break;
case 3: System.out.println("Other's selected"); break;
private void jComboBox4_actionPerformed(ActionEvent e)
int index = jComboBox4.getSelectedIndex();
switch(index)
case 0: System.out.println("One selected"); break;
case 1: System.out.println("Two selected"); break;
case 2: System.out.println("Three selected"); break;
case 3: System.out.println("Four selected"); break;
case 4: System.out.println("Five selected"); break;
private void jComboBox5_actionPerformed(ActionEvent e)
int index = jComboBox5.getSelectedIndex();
switch(index)
case 0: System.out.println("12/12/2004 being selected"); break;
case 1: System.out.println("13/12/2004 being selected"); break;
case 2: System.out.println("14/12/2004 being selected"); break;
private void jComboBox6_actionPerformed(ActionEvent e)
int index = jComboBox6.getSelectedIndex();
switch(index)
case 0: System.out.println("12/11/2004 being selected"); break;
case 1: System.out.println("13/11/2004 being selected"); break;
case 2: System.out.println("14/11/2004 being selected"); break;
public static void main(String[] args)
newssa ssa=new newssa();
//JFrame.setDefaultLookAndFeelDecorated(true);
//JDialog.setDefaultLookAndFeelDecorated(true);
//JFrame frame = new JFrame("SSA Service Scheduler");
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.setJMenuBar(ssa.menuBar);
//frame.getContentPane( ).add(ssa.toolBar, BorderLayout.NORTH);
//frame.getContentPane( ).add(ssa.pane, BorderLayout.CENTER);
//frame.pack( );
//frame.setVisible(true);
try
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
catch (Exception ex)
System.out.println("Failed loading L&F: ");
System.out.println(ex);
But as a O/P ,I am getting menu in a seperate windos and the rest of the combobox and jtable in a seperate window.Kindly help me to solve the application.
VERY URGENT PLEASE..
Thanks in advance
with kind regds
Satheesh.KBut did u mean this as the next problem,Which I will come across..Yes, the second setVisible(true) seemed to be producing a smaller frame behind the main frame.
And your JMenuBar is declared twice, but not sure if this will affect the code - haven't read it all. -
JCombobox with JMenuBar (as drop down menu)
Hello, i'm trying to make a new component (as generic as possible) to display a tree structure in a combo-like style.
So i finally choose a JTextfield to display the current item + a JMenuBar with Menu and MenuItem generated from a TreeModel (i'm not sure this is the better choice to make, but tha's not my present problem).
2 questions :
1) am I reinventing the wheel ???
2) i've got a problem of pack when displaying the compent and i don't find where.
Thanks. Cyril.
So, the code... two main classes : TreeComboBox + ArrowMenu
the TreeComboBox :
package fr.emanation.util.gui.treeComboBox;
import javax.swing.*;
import javax.swing.tree.TreeModel;
import java.awt.*;
import java.awt.event.FocusListener;
public class TreeComboBox<TNode> extends JPanel
private TNode theSelectedNode;
private ArrowMenuBar theMenuBar;
private JTextField theTextField;
private int theCompactWidth;
public TreeComboBox(TreeModel aTreeModel)
new BorderLayout(0, 0);
theTextField = new JTextField();
theTextField.setEditable(true);
theTextField.setBackground(Color.white);
setFocusable(false);
add(theTextField, BorderLayout.CENTER);
MyArrowMenuInvoker anInvoker = new MyArrowMenuInvoker();
theMenuBar = new ArrowMenuBar<TNode>(anInvoker, aTreeModel);
JPanel menuBarPanel = new JPanel(new BorderLayout(0, 0));
menuBarPanel.add(theMenuBar, BorderLayout.CENTER);
add(menuBarPanel, BorderLayout.EAST);
public TNode getNode()
return (TNode) theSelectedNode;
public void setSelectedNode(TNode aNode)
theSelectedNode = aNode;
theTextField.setText(aNode.toString());
public TreeModel getModel()
return theMenuBar.getModel();
public JComponent[] getFocusableComponents()
return new JComponent[]{theTextField, theMenuBar};
//-- JComponent overriden methods
public Dimension getMinimumSize()
final Dimension minSize = super.getMinimumSize();
minSize.width = theCompactWidth;
return minSize;
public void setCompactWidth(final int aCompactWidth)
theCompactWidth = aCompactWidth;
public void setPreferredSize(Dimension aSize)
super.setPreferredSize(aSize);
if (theTextField != null)
theTextField.setPreferredSize(aSize);
public void setForeground(Color fg)
super.setForeground(fg);
if (theMenuBar != null)
for (int index = 0; index < theMenuBar.getComponentCount(); index++)
theMenuBar.getComponents()[index].setForeground(fg);
if (theTextField != null)
theTextField.setForeground(fg);
public void setBackground(Color bg)
super.setBackground(bg);
if (theMenuBar != null)
for (int index = 0; index < theMenuBar.getComponentCount(); index++)
theMenuBar.getComponents()[index].setBackground(bg);
if (theTextField != null)
theTextField.setBackground(bg);
public void setFont(Font aFont)
super.setFont(aFont);
if (theMenuBar != null)
theMenuBar.setFont(aFont);
if (theTextField != null)
theTextField.setFont(aFont);
public void setToolTipText(String aToolTip)
super.setToolTipText(aToolTip);
if (theTextField != null)
theTextField.setToolTipText(aToolTip);
public void setEnabled(final boolean bEnabled)
super.setEnabled(bEnabled);
if (theTextField != null) return;
theTextField.setEnabled(bEnabled);
if (bEnabled)
theTextField.setBackground(Color.WHITE);
else
JLabel tmpLabel = new JLabel();
tmpLabel.setEnabled(false);
theTextField.setBackground(tmpLabel.getBackground());
if (theMenuBar != null)
theMenuBar.setEnabled(bEnabled);
public synchronized void addFocusListener(FocusListener l)
super.addFocusListener(l);
if (theMenuBar != null)
theMenuBar.addFocusListener(l);
if (theTextField != null)
theTextField.addFocusListener(l);
public synchronized void removeFocusListener(FocusListener l)
super.removeFocusListener(l);
if (theMenuBar != null)
theMenuBar.removeFocusListener(l);
if (theTextField != null)
theTextField.removeFocusListener(l);
public boolean isFocusOwner()
if (theMenuBar == null || theTextField == null) return super.isFocusOwner();
boolean bM = (theMenuBar == null) && theMenuBar.isFocusOwner();
boolean bT = (theTextField == null) && theTextField.isFocusOwner();
return (bM || bT);
//-- inner classes
private class MyArrowMenuInvoker implements IArrowMenuInvoker<TNode>
public Component getComponent()
return theTextField;
public void setNode(TNode aNode)
setSelectedNode(aNode);
}the ArrowMenuBar :
package fr.emanation.util.gui.treeComboBox;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.plaf.UIResource;
import javax.swing.tree.TreeModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ArrowMenuBar<TNode> extends JMenuBar
private NodeMenu theMenu;
private TreeModel theModel;
private IArrowMenuInvoker<TNode> theInvoker;
public ArrowMenuBar(IArrowMenuInvoker<TNode> anInvoker, TreeModel aModel)
super();
theModel = aModel;
theInvoker = anInvoker;
TNode root = (TNode) theModel.getRoot();
if (!theModel.isLeaf(root))
theMenu = new ArrowMenu(root);
theMenu.setBackground(new JPanel().getBackground());
MenuItemListener listener = new MenuItemListener();
setListener(theMenu, listener);
add(theMenu);
private void setListener(JMenuItem anItem, ActionListener aListener)
if (anItem instanceof JMenu)
JMenu menu = (JMenu) anItem;
int n = menu.getItemCount();
for (int index = 0; index < n; index++)
setListener(menu.getItem(index), aListener);
else if (anItem != null)
// null means separator
anItem.addActionListener(aListener);
public TreeModel getModel()
return theModel;
public Action getLaunchArrowMenuBarAction()
return new LaunchArrowMenuBarAction();
//-- overrides JComponent
public Dimension getPreferredSize()
return theMenu.getPreferredSize();
private Dimension getItemSize(JMenu aMenu)
Dimension dimension = new Dimension(0, 0);
int n = aMenu.getItemCount();
for (int index = 0; index < n; index++)
Dimension itemD;
JMenuItem item = aMenu.getItem(index);
if (item instanceof JMenu)
itemD = getItemSize((JMenu) item);
else if (item != null)
itemD = item.getPreferredSize();
else
itemD = new Dimension(0, 0); // separator
dimension.width = Math.max(dimension.width, itemD.width);
dimension.height = Math.max(dimension.height, itemD.height);
return dimension;
//--- inner classes
private class LaunchArrowMenuBarAction extends AbstractAction
public LaunchArrowMenuBarAction()
super("...");
public void actionPerformed(ActionEvent e)
if (e.getActionCommand() == "Launch")
System.out.println("Launch");
private class MenuItemListener implements ActionListener
public void actionPerformed(ActionEvent anEvent)
NodeMenuItem item = (NodeMenuItem) anEvent.getSource();
theInvoker.setNode(item.getNode());
theMenu.requestFocus();
private class NodeMenu extends JMenu
private TNode theNode;
public NodeMenu(TNode aNode)
this(aNode.toString(), aNode);
public NodeMenu(String theText, TNode aNode)
super(theText);
theNode = aNode;
add(new NodeMenuItem("[.]", aNode));
for (int index = 0; index < theModel.getChildCount(aNode); index++)
TNode childNode = (TNode) theModel.getChild(aNode, index);
if (theModel.isLeaf(childNode))
add(new NodeMenuItem(childNode));
else
add(new NodeMenu(childNode));
public void setNode(TNode aNode)
theNode = aNode;
public TNode getNode()
return theNode;
private class NodeMenuItem extends JMenuItem
private TNode theNode;
public NodeMenuItem(TNode aNode)
super(aNode.toString());
theNode = aNode;
public NodeMenuItem(String aText, TNode aNode)
super(aText);
theNode = aNode;
public TNode getNode()
return theNode;
private class ArrowMenu extends NodeMenu
// private ArrowIcon theIconRenderer;
private Color shadow = UIManager.getColor("controlShadow");
private Color darkShadow = UIManager.getColor("controlDkShadow");
private Color highlight = UIManager.getColor("controlLtHighlight");
public ArrowMenu(TNode aNode)
super("", aNode);
// theIconRenderer = new ArrowIcon(SwingConstants.SOUTH, true);
setBorder(new EtchedBorder());
// setIcon(new BlankIcon(null, 11));
setHorizontalTextPosition(JButton.LEFT);
setFocusPainted(true);
public void paint(Graphics g)
Color origColor;
boolean isEnabled;
int w, h, size;
w = getSize().width;
h = getSize().height;
origColor = g.getColor();
isEnabled = isEnabled();
g.setColor(getBackground());
g.fillRect(1, 1, w - 2, h - 2);
/// Draw the proper Border
if (getBorder() != null && !(getBorder() instanceof UIResource))
paintBorder(g);
else
// Using the background color set above
g.drawLine(0, 0, 0, h - 1);
g.drawLine(1, 0, w - 2, 0);
g.setColor(highlight); // inner 3D border
g.drawLine(1, 1, 1, h - 3);
g.drawLine(2, 1, w - 3, 1);
g.setColor(shadow); // inner 3D border
g.drawLine(1, h - 2, w - 2, h - 2);
g.drawLine(w - 2, 1, w - 2, h - 3);
g.setColor(darkShadow); // black drop shadow __|
g.drawLine(0, h - 1, w - 1, h - 1);
g.drawLine(w - 1, h - 1, w - 1, 0);
// If there's no room to draw arrow, bail
if (h < 5 || w < 5)
g.setColor(origColor);
return;
// Draw the arrow
size = Math.min((h - 4) / 3, (w - 4) / 3);
size = Math.max(size, 2);
paintTriangle(g, (w - size) / 2, (h - size) / 2,
size, SwingConstants.SOUTH, isEnabled);
// Reset the Graphics back to it's original settings
g.setColor(origColor);
public Dimension getPreferredSize()
return new Dimension(16, 16);
public Dimension getMinimumSize()
return new Dimension(5, 5);
public Dimension getMaximumSize()
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
public void paintTriangle(Graphics g, int x, int y, int size,
int direction, boolean isEnabled)
Color oldColor = g.getColor();
int mid, i, j;
j = 0;
size = Math.max(size, 2);
mid = (size / 2) - 1;
g.translate(x, y);
if (isEnabled)
g.setColor(darkShadow);
else
g.setColor(shadow);
switch (direction)
case NORTH:
for (i = 0; i < size; i++)
g.drawLine(mid - i, i, mid + i, i);
if (!isEnabled)
g.setColor(highlight);
g.drawLine(mid - i + 2, i, mid + i, i);
break;
case SOUTH:
if (!isEnabled)
g.translate(1, 1);
g.setColor(highlight);
for (i = size - 1; i >= 0; i--)
g.drawLine(mid - i, j, mid + i, j);
j++;
g.translate(-1, -1);
g.setColor(shadow);
j = 0;
for (i = size - 1; i >= 0; i--)
g.drawLine(mid - i, j, mid + i, j);
j++;
break;
case WEST:
for (i = 0; i < size; i++)
g.drawLine(i, mid - i, i, mid + i);
if (!isEnabled)
g.setColor(highlight);
g.drawLine(i, mid - i + 2, i, mid + i);
break;
case EAST:
if (!isEnabled)
g.translate(1, 1);
g.setColor(highlight);
for (i = size - 1; i >= 0; i--)
g.drawLine(j, mid - i, j, mid + i);
j++;
g.translate(-1, -1);
g.setColor(shadow);
j = 0;
for (i = size - 1; i >= 0; i--)
g.drawLine(j, mid - i, j, mid + i);
j++;
break;
g.translate(-x, -y);
g.setColor(oldColor);
}Darkness and blindness are away !
First line of the constructor :
public TreeComboBox(TreeModel aTreeModel)
new BorderLayout(0, 0);
}I will reborn as a pumpkin ! -
How do I add a JMenuBar to a GridBagLayout
Hi All,
I've got a GridBagLayout on a JFrame and want to add a menu bar to row 0. How do I do that? What I've tried to do is create a JPanel, add the JPanel (menuPanel) to my GridBagLayout in column 0, row 0, width 4 and height of 1. Then add the JMenuBar (bar) to menuPanel. I get the JPanel on the screen because it takes up space, but now File menu.
Please help.
// create JPanel
menuPanel = new JPanel();
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.weightx = 0;
constraints.weighty = 0;
addComponent(menuPanel, 0, 0, 4, 1); // object, row, column, width, height
// set up menu bar
fileMenu = new JMenu("File");
fileMenu.setMnemonic('F');
newSearch = new JMenuItem("New Search");
newSearch.setMnemonic('N');
fileMenu.add(newSearch);
exit = new JMenuItem("Exit");
exit.setMnemonic('x');
fileMenu.add(exit);
bar = new JMenuBar();
setJMenuBar(bar);
menuPanel.add(bar);Thanks,
KarlYou don't add a MenuBar to the layout, you add directly to the frame using
setJMenuBar(myMenuBar);HTH,
Radish21 -
I am trying to create a simple JMenuBar in the application enlosed below.
I keep getting the following error when ever i compile
"Screen.java": Error #: 300 : method setJMenuBar(javax.swing.JMenuBar) not found in class random.Screen at line 67, column 9". Can some one please enlighten me.
Class Screen is the main class. This is where the GUI is set up. it calls class Canvas which in turn calls class Nodes. GUI draws a bus network which holds a minimum of two nodes and a maximum of 10. The node number is under user control. The aim is to allow a user to select the configure menu to update the number of nodes on display in the GUI.
package random;
import javax.swing.JPanel;
import javax.swing.border.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
* <p>Title: Simulation of the random load balancing algorithm </p
public class Screen extends JPanel {
static int screenWidth = (int)(Toolkit.getDefaultToolkit().getScreenSize().width*0.85);
static int screenHeight = (int)(Toolkit.getDefaultToolkit().getScreenSize().height*0.95);
private Container container;
JButton add;
Canvas canvas;
JMenuBar menubar;
JMenu configure;
Thread animatorThread;
RandomApplet RApplet;
public Screen(RandomApplet RApplet){
this.RApplet = RApplet;
makeGui();
public Screen(){
makeGui();
public void makeGui(){
addMenu();
GridBagLayout gridbag = new GridBagLayout();
setLayout(gridbag);
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(1,1,1,1);
//add drawing canvas
canvas = new Canvas();
c.gridx = 0;
c.gridy = 0;
c.weightx=1.0;
c.weighty=1.0;
c.fill=GridBagConstraints.BOTH;
gridbag.setConstraints(canvas, c);
add(canvas);
c.gridx=0;
c.gridy=1;
gridbag.setConstraints(canvas,c);
add(add=addButton("Add"));
private void addMenu(){
menubar = new JMenuBar();
setJMenuBar(menubar);
configure = new JMenu("Configure");
configure.add(new JMenuItem("add"));
menubar.add(configure);
private JButton addButton(String name) {
JButton b = new JButton(name);
ButtonHandler handler=new ButtonHandler();
b.addActionListener(handler);
b.setFont(new Font("Dialog", Font.BOLD, 12));
b.setMargin(new Insets(0,0,0,0));
return b;
class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
if (e.getSource()== add){
if (canvas.addNode()){
repaint();
public void run(){
Thread thisThread = Thread.currentThread();
while (animatorThread == thisThread){
try {
Thread.sleep(100);}
catch (Exception e){
break;}
public static void main(String[] args) {
JFrame f=new JFrame("Random");
f.setSize(screenWidth, screenHeight);
f.getContentPane().add(new Screen());
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
//class Canvas
package random;
import javax.swing.JPanel;
import java.awt.*;
import java.util.*;
import java.awt.Graphics;
import java.awt.image.*;
import javax.swing.*;
public class Canvas extends JPanel{
int width, height;
Dimension size;
Image canvasImage = null;
Graphics canvasGraphics;
Image networkMem;
int NodeWidth, NodeHeight;
Nodes[] n;
int numberOfNodes;
int x1, y1,x2,y2;
public Canvas(){
// canvas a perfect square
height = 400;
width = 400;
size=new Dimension(width,height);
setBackground(Color.white);
networkMem=Toolkit.getDefaultToolkit().createImage("images/computer6.gif");
NodeWidth = networkMem.getWidth(this);
NodeHeight = networkMem.getHeight(this);
//network must hold a minimum of 2 nodes
n = new Nodes[11];
n[0] = new Nodes(0,this);
n[1] = new Nodes(1,this);
numberOfNodes = 2;
public void paintComponent(Graphics g)
super.paintComponent(g);
//create canvas image
if (canvasImage==null){
canvasImage=createImage(getSize().width,getSize().height);
canvasGraphics = canvasImage.getGraphics();
//adjust above to fit canvas window
if ((canvasImage.getWidth(this) != getSize().width) || (canvasImage.getHeight(this) != getSize().height)){
canvasImage = createImage(getSize().width,getSize().height);
if (canvasImage!=null){
canvasGraphics.dispose();
canvasGraphics = canvasImage.getGraphics();
//create a rectangular border outlining canvas area
canvasGraphics.drawRect(0,0,getSize().width-1,getSize().height-1);
x1=width-100;
y1=height-100;
x2=width-300;
y2=width-100;
canvasGraphics.drawLine(x1,y1,x2,y2);
//canvasGraphics.drawLine(width-300,height-100,width-300,height-50);
//canvasGraphics.drawLine(width-100,height-100,width-100,height-50);
for(int i=0; i<numberOfNodes; i++){
n.drawNode(canvasGraphics);
g.drawImage(canvasImage, 0, 0, this);
super.paintComponent(canvasGraphics);
public int getNumberOfNodes()
return numberOfNodes;
public boolean addNode(){
//add a node to network
if (numberOfNodes < 10) {
n[numberOfNodes]= new Nodes(numberOfNodes, this);
numberOfNodes++;
repaint();
return true;
return false;
public boolean removeNode(){
boolean removed = false;
if (numberOfNodes >2) {
numberOfNodes=numberOfNodes - 1;
removed = true;
else{
removed = false;
repaint();
return removed;
//class Nodes
package random;
import javax.swing.JPanel;
import javax.swing.*;
import java.awt.*;
import java.awt.Graphics;
public class Nodes{
int nodeNumber;
Canvas canvas;
public Nodes(int number, Canvas c) {
//each node has a number id
nodeNumber=number;
canvas=c;
public void drawNode(Graphics g){
if (nodeNumber%2 == 0){
canvas.x1=canvas.x1-10;
System.out.println(""+canvas.x1);
g.drawLine(canvas.x1,canvas.y1,canvas.x1,canvas.y2-50);
g.drawImage(canvas.networkMem,canvas.x1,canvas.y1-80,canvas);
else{
canvas.x1=canvas.x1-30;
System.out.println(""+canvas.x1);
g.drawLine(canvas.x1,canvas.y1,canvas.x1,canvas.y2+50);
g.drawImage(canvas.networkMem,canvas.x1,canvas.y2+50,canvas);Thanks for the reply but i figured it out in the end.
I can make use of the following commands
setMenuBar(MenuBar mb)
getMenuBar()
to set the main frame menubar to that declared in addmenu() .
if I add the following code to main() in the screen class the menu appears
Screen screen = new Screen(null);
f.setJMenuBar(screen.getMenuBar()); -
Adding a JMenuBar to my JViewer
I have a class, JViewer, that extends the JFrame class. When i call the following piece of code, the menubar, mb, should be placed in the JViewer, but it isn't there.
JViewer viewer = (JViewer) getViewer();
JMenuBar mb = getMenuBar();
viewer.setMenuBar(mb);
The setMenuBar in the JViewer code looks like the following
public void setMenuBar(JMenuBar menu) {
this.getContentPane().add(menu);
I have already tried simply using the JFrame method setJMenuBar, but it also does not work.
Any ideas???
Stepheni know that the JMenuBar, mb, has all the necessary components in it, but it's just not being added using the line
viewer.setMenuBar(mb);
again, setMenuBar is
public void setMenuBar(JMenuBar menu) {
this.getContentPane().add(menu);
and the code for JViewer is (but i don't think it will be of any use that much, except to confirm that i am extending JFrame). I also implement my own Viewer interface, which is also at the bottom.
package com.bmw.nasa.gui;
import java.awt.*;
import java.beans.*;
import java.awt.event.*;
import com.bmw.nasa.gui.*;
import com.bmw.nasa.global.*;
import com.rsr.swing.UserInterfaceUtilities;
import javax.swing.*;
import javax.swing.event.EventListenerList;
public class JViewer extends JFrame
implements Viewer {
JViewerPanel currentPanel;
Dimension minimumSize = new Dimension(790, 568);
/** event support*/
private EventListenerList listenerList = new EventListenerList();
JDialog aboutbox;
//Construct the frame
public JViewer() {
this.setSize(new Dimension(790, 568));
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
quit();
public void windowClosed(WindowEvent e) {
quit();
addComponentListener( new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
Component component = e.getComponent();
Dimension currentSize = component.getSize();
boolean adjust = false;
if ( minimumSize != null ) {
if ( currentSize.width < minimumSize.width ) {
currentSize.width = minimumSize.width;
adjust = true;
if ( currentSize.height < minimumSize.height ) {
currentSize.height = minimumSize.height;
adjust = true;
if ( adjust )
component.setSize(currentSize);
//System.err.println("Rezized: " + currentSize + "," + component);
// Create keystrokes and assign them
// (1) F1 anywhere in the window
this.getRootPane().registerKeyboardAction(
new ActionListener() {
public void actionPerformed(ActionEvent evt) {
showVersionWindow();
KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK | Event.ALT_MASK , false),
JComponent.WHEN_IN_FOCUSED_WINDOW
try {
this.getContentPane().setLayout(new BorderLayout());
this.setTitle("NASA-iX");
catch (Exception e) {
e.printStackTrace();
public void activate() {
validate();
if ( currentPanel != null )
currentPanel.activate();
setVisible(true);
public void addViewerListener(ViewerListener l) {
listenerList.add(ViewerListener.class, l);
public void expose() {
setVisible(true);
public void fireViewerDone(ViewerEvent e) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners==ViewerListener.class) {
((ViewerListener)listeners[i+1]).viewerDone(e);
public void fireViewerStarted(ViewerEvent e) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==ViewerListener.class) {
((ViewerListener)listeners[i+1]).viewerStarted(e);
public Viewer getAnotherViewer() {
JViewer viewer = new JViewer();
viewer.setSize(getSize());
return viewer;
public void quit() {
if (currentPanel != null) {
currentPanel.quit();
fireViewerDone(new ViewerEvent(this));
public void removeViewerListener(ViewerListener l) {
listenerList.remove(ViewerListener.class, l);
public void setMenuBar(JMenuBar menu) {
this.getContentPane().add(menu);
public void setMinimumSize(Dimension minimumSize) {
Dimension old = this.minimumSize;
this.minimumSize = minimumSize;
firePropertyChange("minimumSize", old, minimumSize);
public void setPanel(JViewerPanel panel) {
if (currentPanel!=null) {
this.getContentPane().remove(currentPanel);
if ( currentPanel instanceof TitleChangedListener )
currentPanel.removeTitleChangedListener(this);
currentPanel = panel;
this.getContentPane().add(currentPanel, BorderLayout.CENTER);
String title = panel.getTitle();
if ( title != null) {
setTitle(title);
if (currentPanel instanceof TitleChangedListener )
currentPanel.addTitleChangedListener(this);
validate();
repaint();
public void showVersionWindow() {
if ( aboutbox == null )
aboutbox = new AboutBox(this,"Info", true);
aboutbox.show();
public void showVersionWindow1() {
JFrame f = new JFrame("Version");
f.show();
public void titleChanged(TitleChangedEvent e) {
this.setTitle(e.getTitle());
repaint();
//Viewer
package com.bmw.nasa.gui;
import java.awt.*;
public interface Viewer extends TitleChangedListener {
public void activate();
public void addViewerListener(ViewerListener l);
public void expose();
public Viewer getAnotherViewer();
public void quit();
public void removeViewerListener(ViewerListener l);
public void setPanel(JViewerPanel panel);
public void setMenuBar(javax.swing.JMenuBar menu); -
To setBorder for JMenu Object when JMenuBar Object's border is also set
Hi,
I have created a JMenuBar Object mb and have set its border as
mb.setBorder(new EmptyBorder(-3,-3,-3,-3)); // have given negative values so that the height of the Menubar decreases since i wanted a narrow menubar.
Also cretaed a JMenu Object-menu . and now i want to set the border of this Menu Object as simple lineborder.
menu.setBorder(BorderFactory.createlineborder(Color.black) );
But the border is not seen fully. Only the left and right vertical border is seen. Top and bottom horizontal border is not seen.
The moment i make the negative values to positive in EmptyBorder or for that matter i comment that line and do not set EmptyBorder for the Menubar then --the whole border is seen properly.
So, how do i make the border wholly visible and with a narrow menubar...
Thanks and regardsFrom the JMenuBar API it looks like you could use setMargin(...);
-
AffineTransform problem caused by JMenuBar + JTabbedPane
Hello everyone.
I am starting to think that there is a bug in Java, because otherwise what else could cause the problem I am experiencing? Namely: adding a panel with a vertical text (like a Y axis caption) using an AffineTransform (see SSCCE below) causes this text to be misplaced in some cases.
Variant A
Panel is added directly to the application frame. This causes no problems and everything is as it should be.
Variant B
Panel is placed on a tabbed pane and a menu bar is associated with the frame. The vertical text is now shifted away from the place where it should be by the height of the menu bar plus the height of tabs on the tabbed pane. Why is this happening? Am I doing something wrong?
Moreover, when one switches to another tab and then back, the text is now shifted only by the height of the tabs. Once the application window is resized at least a bit, the text jumps right back to the position shifted by tab height plus menu bar height... Strange, strange, strange...
SSCCE
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.*;
import javax.swing.*;
class MyPanel extends JPanel {
MyPanel() {
this.setPreferredSize(new Dimension(300, 200));
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2D = (Graphics2D)g;
int g2DWidth = this.getWidth();
int g2DHeight = this.getHeight();
// Horizontal line in the middle of the panel (indicates the position
// where the middle of the vertical label should be)
g2D.drawLine(30, (int)(g2DHeight / 2), g2DWidth - 10,
(int)(g2DHeight / 2));
// Vertical label
AffineTransform origTransform = g2D.getTransform();
AffineTransform rotate = AffineTransform.getRotateInstance(
-Math.PI / 2.0, 0, 0);
g2D.setTransform(rotate);
String text = "Centered?";
FontRenderContext frc = g2D.getFontRenderContext();
Font font = UIManager.getFont("Label.font");
Rectangle2D bounds = font.getStringBounds(text, frc);
g2D.drawString(text, -(int)((g2DHeight + bounds.getWidth()) / 2), 20);
g2D.setTransform(origTransform);
class Main {
private static void createAndShowGUI() {
// Menu bar
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Menu");
JMenuItem menuItem = new JMenuItem("Menu Item");
menu.add(menuItem);
menuBar.add(menu);
// Tabbed pane
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panel = new MyPanel();
tabbedPane.add(panel);
JLabel label = new JLabel("Nothing interesting's going on here...");
tabbedPane.add(label);
// Frame
JFrame frame = new JFrame();
// TRICKY PART HERE =========================================
// [(Un)comment lines as necessary]
// Variant A: the panel only --------------------------------
//frame.add(panel);
// Variant B: menu bar + panel on a tabbed pane -------------
frame.setJMenuBar(menuBar);
frame.add(tabbedPane);
// ==========================================================
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}Thanks for any help.
Best regards,
vt
Edited by: -vt- on 23-Apr-2010 13:08You are ignoring the current transform on the Graphics, use the following instead of setTransform():
g2D.rotate(-Math.PI / 2.0, 0, 0); -
JMenuBar causes setExtendedState(Frame.MAXIMIZED_BOTH) to not work?
Hello folks,
I'm trying to teach myself Java Swing and I'm going through the tutorials and trying to create little applications as a learning process.
Originally, my intent for this little dummy application of mine was for it to load up maximized. After some searching, I found that you can use setExtendedState(Frame.MAXIMIZED_BOTH);
This worked great until I wanted to create a menu bar. I added JMenuBar and it seems to nullify what I had done before with the setExtendedState.
The problem seems to be with frame.pack();
If I remove the pack function then the screen starts out maximized with the menu bar. If I add it in, then the screen loads up fitted, and when minimized, the frames seem to have no width/height.
Can someone please give me some advice on how I could load up the screen maximized with the menu bar? And when unmaximized (but not minimized), the screen has a reasonable width/height?
Thanks in advance.HI ,
Actually i also have the same problem, i am creating a gui with four splits . i want the frame to extend to the maximum position when maximize is clicked.
plz help me out what to use actually to make my screen flexible to minimum nd maximum positions.
thanks
swathi. -
Closing Terminal window tabs shrinks Terminal window height
Open a Terminal window, press Command-T to create a tab, and then Ctrl-D to close that new tab, the Terminal window height decreases by one row.
This most certainly appears to be a bug. How do I report this to Apple?I am also experiencing this problem, however if you use the Basic setting the problem doesn't exist.
I am using Novel and I have the problem. It's quite annoying.
I noticed that if you set the fontsize to 12 then this problem exhibits, however if I change the size to 11pt or 10pt (10 is the default for Basic, 12 is default for Novel) then I don't have the bug.
Message was edited by: TonyKL -
Print the report on page has width larger than height and not landscape mode
Hi,
I'm trying to print report on page (Width: 18cm, Height: 13cm) which the width larger than the height.
The problem is windows keeps changing the page oreintation to landscape and when I change it back to portrait its changing the width to 13cm and height to 18cm.
I'm using dot matrix printer to print the report, if i put Landscape , printer is printing the text in horizontal.
Already i have tried to setup the custom for on printer, and used custom page size but it is changing to landscape.
I need to print the report with out preview, direct print top printer, NO PDF....
Thank you .....Hi Anil,
After testing the issue in my environment, I can reproduce it. When I set (Width: 18cm, Height: 13cm) as the Report Page size, it would automatically convert Orientation from Portrait to Landscape. Because the Orientation displayed is dependent on the page
width and page height of the report.
But in my scenario, the Orientation option just change the Width and Height sizes, it couldn’t affect the text rotation. I guess this issue can be caused by the printer and printer driver, please try to update them. Reference:
http://stackoverflow.com/questions/15244336/printing-in-landscape-or-portrait-automatically-rotates-text-ssrs?lq=1
Hope this helps.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Can i call a JMenuBar in a number of JFrame(s) ?
Hi ,
I've a program with a number of JFrames.
I wanted to add a JMenuBar for each frame of my program, this menu bar has the same design code and the same events code in all the program frames, so is there a way to create this JMenuBar once only & call it some how in every JFrame to load it directly instead of writing its same code a lot of times for every JFrame ?
Thanks ,
Heshamimport java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
class Test{
public static void main( String[] argv ) throws Throwable {
for(int i=0; i<10; i++){
SuperFrame f = new SuperFrame();
f.setLocation(i*10,i*10);
f.setSize(400,300);
f.setVisible(true);
class SuperFrame extends JFrame{
private static final long serialVersionUID = 1L;
* All the menu item goes here
JMenuBar mbar = new JMenuBar();
JMenu menu = new JMenu("Menu");
JMenuItem menuItem1 = new JMenuItem("Close");
JMenuItem menuItem2 = new JMenuItem("Exit");
public SuperFrame(){
super("Testing");
this.menu.add(menuItem1);
this.menu.add(menuItem2);
this.mbar.add(menu);
this.setJMenuBar(mbar);
menuItem1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
dispose();
menuItem2.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
Maybe you are looking for
-
Problem with stock transport order account assignment
hi gurus, I've a situation in ECC 6.0 environment in regard to STO that I hope you can shed some lights. We're doing an upgrade from 4.6 to ECC6 and I'm doing some preliminary tests in the new box and I'm getting KI235 error message "Account xxx requ
-
How do i get a refund from the apple store?
how do i get a refund from the apple store. I hate the Final Cut Pro. I tried to contact costumer service and all it does is send me in circles
-
Permissions for files saved on another machine's shared disk
I'm having problems with permissions on files that I create on my Macbook but save on my Mini. They are all created as read only for everyone except me, which rather defeats the purpose of having the shared directory on the Mini. I want to change the
-
hi gurus, I have to use array for some calculations. I begin new project and have to calculate distance with using array. I searched forums but I found nothing. please help me? thanks,
-
Can't install photoshop. Asks for IE 4 or greater. I have IE 11, in emulation mode for IE8. Still won't install.