[ Back | Previous | Next ]

How to use LayoutManager as innerclass as template?

Package:
java.awt.*
Product:
1.1.x
Release:
JDK
Related Links:
Color
Cursor
FileDialog
Font
FontMetrics
Frame
general
Image
LayoutManager
Menu
ScrollPane
Comment:
	setLayout(new LayoutManager() {
		public void addLayoutComponent(String name, Component comp) {
		}
		public void removeLayoutComponent(Component comp) {
		}
		//
		public Dimension preferredLayoutSize(Container target) {
			return new Dimension(10, 10);
		}
		//
		public Dimension minimumLayoutSize(Container target) {
			return new Dimension(10, 10);
		}
		public void layoutContainer(Container target) {
			Insets insets = target.getInsets();
			int nmembers = (target.getComponentCount() <= 3 ? target.getComponentCount() : 3);
			int border = 5;
			int top = insets.top + border;
			int bottom = target.getSize().height - insets.bottom - border;
			int left = insets.left + border;
			int right = target.getSize().width - insets.right - border;

			//target.reshape( left, top, right - left, bottom - top);
			//target.setBackground(Color.red);
			//System.out.println("listlayout: targetsize: " + getDim(target));
			int[] perc = {40, 20, 40};
			int maxwidth = right - left;
			int w = 0, h = 0;
			for (int i = 0; i < nmembers; i++) {
				Component m = target.getComponent(i);
				//System.out.println("listlayout comp #" + i + " " + getDim(m) + "..pref=" + getDim(m.getPreferredSize()));
				Dimension d = m.getPreferredSize();
				int width = maxwidth * perc[i] / 100;
				System.out.println("" + width);
				m.setBounds(left, top, width, d.height);
				left += (maxwidth * perc[i] / 100)+border;
			}
		}
	});
1