Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » [Swing] Custom tab problem
icon4.gif  [Swing] Custom tab problem [message #1694910] Fri, 08 May 2015 21:04
Eclipse UserFriend
Hi. I'm making my own application window using an undecorated frame.

For the application window, I'm making my own tabs by using 2 labels for each tab option. One for the tab texture, and one for the tab name. Currently, I've only have the File and Edit tabs for now.
I'm trying to make it so when I click lblFile, the tabFile (which is behind lblFile) changes the label icon to the "tab_selected" image. I've managed to so this, but it appears as an error.
For some reason, eclipse won't allow me to do this because tabFile is behind lblFile.

Is there anyway to get around this?

Edit: Here's the code for my File and Edit tab. By the way, they are in a jPanel
JLabel lblEdit = new JLabel("Edit");
lblEdit.setForeground(new Color(0, 0, 0));
lblEdit.addMouseListener(new MouseAdapter() {
	@Override
	public void mouseClicked(MouseEvent e) {
		file = false;
		tabFile.setVisible(false); // The line shows up as an error.
		lblFile.setForeground(new Color(0, 0, 0));
		edit = true;
		tabEdit.setVisible(true); // The line shows up as an error.
		lblEdit.setForeground(new Color(255, 255, 255));
	}
	@Override
	public void mouseEntered(MouseEvent e) {
		if(edit == false) {
			lblEdit.setForeground(new Color(255, 255, 255));
		}
	}
	@Override
	public void mouseExited(MouseEvent e) {
		if(edit == false) {
			lblEdit.setForeground(new Color(0, 0, 0));
		}
	}
});
lblEdit.setVerticalAlignment(SwingConstants.TOP);
lblEdit.setHorizontalAlignment(SwingConstants.CENTER);
lblEdit.setBounds(53, 1, 44, 26);
barMenu.add(lblEdit);

JLabel lblFile = new JLabel("File");
lblFile.setForeground(new Color(255, 255, 255));
lblFile.addMouseListener(new MouseAdapter() {
	@Override
	public void mouseClicked(MouseEvent e) {
		file = true;
		tabFile.setVisible(true); // The line shows up as an error.
		lblFile.setForeground(new Color(255, 255, 255));
		edit = false;
		tabEdit.setVisible(false); // The line shows up as an error.
		lblEdit.setForeground(new Color(0, 0, 0));
	}
	@Override
	public void mouseEntered(MouseEvent e) {
		if(file == false) {
			lblEdit.setForeground(new Color(255, 255, 255));
		}
	}
	@Override
	public void mouseExited(MouseEvent e) {
		if(file == false) {
			lblEdit.setForeground(new Color(0, 0, 0));
		}
	}
});
lblFile.setVerticalAlignment(SwingConstants.TOP);
lblFile.setHorizontalAlignment(SwingConstants.CENTER);
lblFile.setBounds(2, 1, 44, 26);
barMenu.add(lblFile);

JLabel tabEdit = new JLabel(); // Don't really need "" as I'm using this for an image.
tabEdit.setVisible(false);
tabEdit.setIcon(new ImageIcon(CustomTab.class.getResource("/dtaylormedia/customtab/assets/tabs/tabEdit.png")));
tabEdit.setBounds(50, 0, 49, 31);
barMenu.add(tabEdit);

JLabel tabFile = new JLabel(); // Don't really need "" as I'm using this for an image.
tabFile.setIcon(new ImageIcon(CustomTab.class.getResource("/dtaylormedia/customtab/assets/tabs/tabFile.png")));
tabFile.setBounds(0, 0, 46, 31);
barMenu.add(tabFile);

[Updated on: Sat, 09 May 2015 09:39] by Moderator

Previous Topic:Using ASTParser for Android libraries
Next Topic:Page generation in Firefox
Goto Forum:
  


Current Time: Mon Apr 21 00:24:51 EDT 2025

Powered by FUDForum. Page generated in 15.09921 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top