Re: How to get tab height?
Todd wrote:
I'm curious though why you need to know?
I am likely doing something wrong, so if you have a better idea
following my reasoning, I would love to hear it.
I have a JTabbedPane which holds other JTabbedPanes. Each
tab of the embedded pane contains one or more panels. I have
been calculating the height of the embedded pane based upon
the panels it contains, then setting size, preferredSize, and
minimumSize of the embedded pane.
Once that is done, the outer pane's size is then based upon
the largest embedded pane. However, when I request the height
of the embedded pane, it returns the panel height, not including
the tab height. Hence, my need for the tab height ~ to add it
to the panel height to get the total embedded pane height. That
total height is then used to set the size, preferredSize, and
minimumSize of the outer pane.
I will play with the UI info to see how that goes.
Thanks,
Todd
You can use a layoutmanager to layout your panels. The tabbed pane will
size itself to the largest one. In the example below the panels don't
have any components so I size them specifically. The tabbed pane sizes
itself to fit the largest. The layout manager used by JTabbedPane sizes
the panel to fit the room available, that's why they are all the same
size when you look at them. If the panels are bigger than what you want
your frame to be you can always put them in a JScrollPane.
So I wouldn't worry about the size of the tabs.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTabbedPane outer = new JTabbedPane();
JTabbedPane inner = new JTabbedPane();
System.out.println(inner.getLayout());
JPanel red = new JPanel();
red.setBackground(Color.RED);
red.setPreferredSize(new Dimension(400,300));
JPanel green = new JPanel();
green.setBackground(Color.GREEN);
green.setPreferredSize(new Dimension(200,150));
JPanel yellow = new JPanel();
yellow.setBackground(Color.YELLOW);
yellow.setPreferredSize(new Dimension(100,75));
inner.addTab("Red",red);
inner.addTab("Green",green);
inner.addTab("Yellow",yellow);
outer.addTab("Outer",inner);
f.add(outer,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
});
}
}
--
Knute Johnson
email s/nospam/knute2008/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access