Making label have precedence over other objects.

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 647 Views - Last Post: 26 July 2019 - 03:38 AM Rate Topic: -----

#1 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Making label have precedence over other objects.

Posted 23 July 2019 - 07:32 AM

Here is my problem: I have a Label object that is a solid gray color and I am using it for design in my program. But I also have a JLabel that is an icon and when they bump into each other, the JLabel icon blanks out the solid gray. I don't know the term for what I am looking for but I want the JLabel to act in the background of the Label.

In case anyone is wondering why I used a Label object rather than a JLabel, it is because I don't know how to fill the JLabel with a solid color.

If anyone could tell me how to solve my problem, it'd be awesome!

	private void initialize() {
		frmDatabaseConnector = new JFrame();
		frmDatabaseConnector.setBackground(SystemColor.window);
		frmDatabaseConnector.setIconImage(Toolkit.getDefaultToolkit().getImage(sqlPracticeGui.class.getResource("/images/HyVee.png")));
		frmDatabaseConnector.getContentPane().setBackground(Color.WHITE);
		frmDatabaseConnector.getContentPane().setForeground(Color.WHITE);
		frmDatabaseConnector.setTitle("DataBase Connector ");
		frmDatabaseConnector.setBounds(100, 100, 520, 400);
		frmDatabaseConnector.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmDatabaseConnector.getContentPane().setLayout(null);
		
		JButton btnLogin = new JButton("");
		btnLogin.setBackground(Color.WHITE);
		btnLogin.setOpaque(false);
		btnLogin.setBorderPainted(false);
		btnLogin.setContentAreaFilled(false);
		btnLogin.setSelectedIcon(new ImageIcon("C:\\Users\\dakot\\OneDrive\\Pictures\\Icons\\enter.png"));
		Image img = new ImageIcon(this.getClass().getResource("/enter16px.png")).getImage();
		btnLogin.setIcon(new ImageIcon(sqlPracticeGui.class.getResource("/images/redlogin64.png")));
		btnLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				frmDatabaseConnector.dispose();
				LoginFrame.getWindows();
				obj2.setVisible(true);
				
			}
			
		});
		btnLogin.setBounds(399, 268, 97, 92);
		frmDatabaseConnector.getContentPane().add(btnLogin);
		
		JLabel lblNewLabel = new JLabel("New label");
		lblNewLabel.setBackground(Color.WHITE);
		lblNewLabel.setOpaque(true);
		lblNewLabel.setIcon(new ImageIcon(sqlPracticeGui.class.getResource("/images/hyvee2.png")));
		lblNewLabel.setBounds(90, 0, 416, 283);
		frmDatabaseConnector.getContentPane().add(lblNewLabel);
		
		Label label = new Label("");
		label.setBackground(Color.LIGHT_GRAY);
		label.setBounds(0, 0, 89, 374);
		frmDatabaseConnector.getContentPane().add(label);
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Making label have precedence over other objects.

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15170
  • View blog
  • Posts: 60,715
  • Joined: 12-June 08

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 07:40 AM

Quote

In case anyone is wondering why I used a Label object rather than a JLabel, it is because I don't know how to fill the JLabel with a solid color.

Another case where hitting up the help docs would.. well.. help.

Search terms "JLabel docs"
-> https://docs.oracle....ing/JLabel.html
and.. https://docs.oracle....ents/label.html

Since you are looking to deal with the background then, control+f "background"
Was This Post Helpful? 0
  • +
  • -

#3 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,858
  • Joined: 25-December 13

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 07:43 AM

Did you read the API doc for the class to see if any of them would set the background color?
Don't forget to look at all the classes that are extended.

This post has been edited by NormR: 23 July 2019 - 07:43 AM

Was This Post Helpful? 0
  • +
  • -

#4 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 12:42 PM

Anybody want to give me any advice that helps? Like I said I don't even know what the function I am looking for would be called. I need to be able to make something show in front of other things as a default and vice versa... What is that called, how do I do it, is it possible? That is all I am asking.
Was This Post Helpful? 0
  • +
  • -

#5 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,858
  • Joined: 25-December 13

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 12:46 PM

Quote

something show in front of other things

That could describe zordering. There are methods in the Container class for that.

Pass "set zorder java" to Google for some discussions.

This post has been edited by NormR: 23 July 2019 - 12:47 PM

Was This Post Helpful? 1
  • +
  • -

#6 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15170
  • View blog
  • Posts: 60,715
  • Joined: 12-June 08

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 12:46 PM

Quote

I also have a JLabel that is an icon and when they bump into each other, the JLabel icon blanks out the solid gray.

This doesn't make sense. Please clarify the issue.
Was This Post Helpful? 0
  • +
  • -

#7 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 12:48 PM

When my two labels, regardless of class, come into contact and one is superimposed over the other, One obviously covers the other one up. So if I want to
A) Make one of my labels always be the one that gets superimposed over
B) Make one of my labels always be superimposed over another label
C) Make one label superimpose over another in a specific order for one particular instance
How would I do any of these 3 things?
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15170
  • View blog
  • Posts: 60,715
  • Joined: 12-June 08

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 12:50 PM

Are you moving your labels, on the screen, with a mouse click or button click? Like a game? I am not getting why two labels plopped on a GUI would arbitrarily coming in contact with each other.
Was This Post Helpful? 0
  • +
  • -

#9 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 12:56 PM

Yes I am using Eclipse. And no it is not like a game. I am trying to overlay them for a GUI design, I obviously don't know much about design so this is my solution...
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15170
  • View blog
  • Posts: 60,715
  • Joined: 12-June 08

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 01:02 PM

Continue on. What design needs overlaid labels? Do you have a screen shot?

As it was mentioned above, yes, probably a 'z order' thing.

Head to the handy oracle docs on 'jlabel' and search for 'order' and see about what's been inherited for the 'z' depth.

https://docs.oracle....ing/JLabel.html
Was This Post Helpful? 0
  • +
  • -

#11 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 01:03 PM

I attached the screenshot
You can notice what I am trying to do on the left with the gray.

Attached image(s)

  • Attached Image

This post has been edited by dako: 23 July 2019 - 01:04 PM

Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15170
  • View blog
  • Posts: 60,715
  • Joined: 12-June 08

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 01:06 PM

No, not really. What is the gray stuff? What is a label on there? What isn't?

Never mind.. I thought a screen shot would help.. but no, go poke around the 'zorder' suff.
Was This Post Helpful? 0
  • +
  • -

#13 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 01:11 PM

You seem incapable of just saying "Sorry man I really don't know." Then you turn it around on the person asking for help in a demeaning and patronizing way.

Also, you have literally posted a response on every single thread I have posted, and not a single time have you provided something even reminiscent to a solution. You trying to get your post count up bro?
Was This Post Helpful? -1
  • +
  • -

#14 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15170
  • View blog
  • Posts: 60,715
  • Joined: 12-June 08

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 01:15 PM

Ease up there chief. I am looking for clarification, and not trying to be patronizing or demeaning.
Was This Post Helpful? 0
  • +
  • -

#15 dako   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 60
  • Joined: 01-July 19

Re: Making label have precedence over other objects.

Posted 23 July 2019 - 01:17 PM

"Never mind.. I thought a screen shot would help.. "

"Are you moving your labels, on the screen, with a mouse click or button click? Like a game?"

"Another case where hitting up the help docs would.. well.. help."
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2