🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.java.api
3 messages
3 total messages Started by Henrik Wahlberg Wed, 24 Nov 1999 00:00
SWING, layout relationship problem, how do i fix this sample?
#16
Author: Henrik Wahlberg
Date: Wed, 24 Nov 1999 00:00
147 lines
4787 bytes
This is a multi-part message in MIME format.
--------------CAFF8DBCE0336FC7EC19F6D2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi.

I'm trying to make i combo panel similar to the tabpane, but with the tabs replaced by a Combobox.
To achieve this I have subclassed a JPanel, called PDropDownPane. In this I setup a borderlayout, and add a combobox in the top (NORTH) and a cardlayout in CENTER.

To test it, I add this panel to a JFrame center, and add an "ADD" button on the NORTH border, to test adding panels dynamically. This snip is placed in DDTest.java.

The problem is, that the combobox gets overlayed (most of the time) by the cardpane layout, which then leaves a blank(gray) area in the SOUTH border region, same height as the combobox or the ADD button.

Before loosing all of my hair, please look at my code??

Is there a tool to visualize the "window" relationship ?. On MS Windows i had a tool to do this kind of spying, but I belive it's no good for swing.


--

MVH/Regards Henrik Wahlberg, EDB Gruppen A/S.
  henrik.wahlberg.#.herning.mail.telia.com (Replace .#. with @)


--------------CAFF8DBCE0336FC7EC19F6D2
Content-Type: text/plain; charset=us-ascii;
 name="PDropDownPane.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="PDropDownPane.java"


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

public class PDropDownPane extends JPanel {
	JComboBox selector; //frame.north has combobox to select which pane is shown below
	JPanel layoutArea; //frame.center will contain this panel with cardlayout manager
		
public PDropDownPane()     {
	setLayout(new BorderLayout());
			
	selector = new JComboBox();
	selector.addItemListener(new ItemListener() {
		public void itemStateChanged(ItemEvent e) {
			if (e.getStateChange() == ItemEvent.SELECTED) {
				selectLayout(e.getItem().toString());
			}
		}
	});
	add(selector, BorderLayout.NORTH);
	
	layoutArea = new JPanel(new CardLayout());
	add(layoutArea, BorderLayout.CENTER);

}

public void addTab(String a, Icon b, JComponent c, String d) { 
	selector.addItem(a);
	layoutArea.add(c,a);
	c.setToolTipText(a);
	this.repaint();
}

public Component getComponent(int index) {
	return layoutArea.getComponent(index);
}

public int getSelectedIndex() {
	return selector.getSelectedIndex();
}

void selectLayout(String layout) {
	((CardLayout)layoutArea.getLayout()).show(layoutArea, (String)layout);
}

public void   setSelectedIndex(int nChild) {
	selector.setSelectedIndex(nChild);
}
}

--------------CAFF8DBCE0336FC7EC19F6D2
Content-Type: text/plain; charset=us-ascii;
 name="DDTest.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="DDTest.java"


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class DDTest extends JFrame {
	PDropDownPane dd = null;
	int nChild = 0;

public DDTest() {
	super();
	init();
}

public DDTest(String title) {
	super(title);
	init();
}

public void init() {
	dd = new PDropDownPane();
	getContentPane().add(dd, BorderLayout.CENTER);
	addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent e) {
			System.exit(0);
		}
	});

	//Add some initial pages
	for (int n = 1; n < 5; n++) {
		JTree jt = new JTree();
		dd.addTab("Startup "+n, null, jt, "Startup "+n);
	}	

	//Add an "ADD" button to add panels at runtime
	JButton addButton = new JButton("Add");
	getContentPane().add(addButton, BorderLayout.NORTH);
	ActionListener addAction = new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			JTree jt = new JTree();
			nChild++;
			dd.addTab("Dynamic "+nChild, null, jt, "Dynamic "+nChild);
			dd.setSelectedIndex(nChild);
		}
	};
	addButton.addActionListener(addAction);
}

public static void main(String[] args) {
	DDTest f = new DDTest("GridLineLayoutTest");
	f.setSize(600, 400);
	f.setLocation(100, 100);
	f.setVisible(true);
}
}
--------------CAFF8DBCE0336FC7EC19F6D2--
Re: SWING, layout relationship problem, how do i fix this sample?
#17
Author: Henrik Dahl Hansen
Date: Thu, 25 Nov 1999 00:00
24 lines
1733 bytes
Henrik Wahlberg wrote:
> 
> Hi.
> 
> I'm trying to make i combo panel similar to the tabpane, but with the tabs replaced by a Combobox.
> To achieve this I have subclassed a JPanel, called PDropDownPane. In this I setup a borderlayout, and add a combobox in the top (NORTH) and a cardlayout in CENTER.
> 
> To test it, I add this panel to a JFrame center, and add an "ADD" button on the NORTH border, to test adding panels dynamically. This snip is placed in DDTest.java.
> 
> The problem is, that the combobox gets overlayed (most of the time) by the cardpane layout, which then leaves a blank(gray) area in the SOUTH border region, same height as the combobox or the ADD button.
> 
> Before loosing all of my hair, please look at my code??
> 
> Is there a tool to visualize the "window" relationship ?. On MS Windows i had a tool to do this kind of spying, but I belive it's no good for swing.


Hi Henrik,

Your code's ok, just remove the getComponent() method.

Regards
Henrik Dahl Hansen
IBM Denmark
hdh_NS@dk.ibm.com (remove _NS to reply)
Re: SWING, layout relationship problem, how do i fix this sample?
#18
Author: Henrik Wahlberg
Date: Fri, 26 Nov 1999 00:00
19 lines
1186 bytes
Henrik Dahl Hansen wrote:

> Hi Henrik,
>
> Your code's ok, just remove the getComponent() method.
>
> Regards
> Henrik Dahl Hansen
> IBM Denmark
> hdh_NS@dk.ibm.com (remove _NS to reply)

Mange tak..
Jeg var ikke klar over at jeg overstyrede en standard metode.
Så nu må jeg lige have dem renamet.

--

MVH/Regards Henrik Wahlberg, EDB Gruppen A/S.
  henrik.wahlberg.#.herning.mail.telia.com (Replace .#. with @)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads