Placing a component on the face of Another component in java netbeans - java

I'm Facing a problem while I try to add a label on the face of just another label in Java Netbeans. Every time I add a label just above of another label the new label (say label2) automatically goes to the leftmost side and shrink my first label( say label1). Actually, I want to add a background color blue to the top of the form as there are no other possible ways (as I know) to change certain parts of the form to another color I use this way. If there is another way of changing the background of certain parts of a form, share with me. But also help to add a label just above another label.
Thanks in advance .. :)
The following Image will show you my intention. Notice only to the head. There is a label on the left side of a blue label. I want to add that label on the surface of the blue label.
This is the image of Interface which I want to gain in JAVA. This is a Visual Basic MDI Form and list of options are available on the rightmost side. That's what I try to do but couldn't do yet.

Related

Java jframe increase look and feel (flat look)

i'm new to JAVA and i need to know how can i design my jframe like this.this look is when i creating my java project
and this look is after run the programe,
how can i create my java jframe looks like flat look,like this ...
how you are increase your java application more beautiful :)
There is a few things to do to get your frame looking as close as possible to the show one, ill bullet point each step and post examples below
First for the color background, you are going to need to do this for the outside panel (the one holding the login label and the username/password panel) and then also the username/password panel.
Second you are going to need to add borders to both panels, for the first one you are just going to need to add a simple line border and set the color to white. For the second inner panel, it looks like you already have an etched border but you want to change that to createTitleBorder where you can state the border you wish to choose and the title which will be "Login"
Next you are going to want to set the text to white, do this by changing your JLabels text to white using JLabel.setForegroundColor.
Lastly you want to change the textbox background color to dark blue using JTextField.setBackground(//blue color).
Code Example
//BackgroundColor
myLabel.setBackgroundColor(//your color);
//Border one
myPanel.setBorder(BorderFactory.createLineBorder(Color.White));
//Border two
myPanel.setBorder(BorderFactory.createTitleBorder(//your border choice, "Login");
//Set text color
myLabel.setForegroundColor(Color.White);
//Change textbox background color
myTextBox.setBackground(//blueColor);
Hope this helps, if you have an issues just ask.

SWT button position after resizing

I'm working with SWT. I created a button, and it supposed to change its text after being pressed.
The second text is wider than the first one, and the button does not being re-sized appropriately.
so I used button.pack(), and setSize() functions. The real issue is actually with its alignment in the shell after this size changing.
it's being expanded to the right instead to the left.
I guess it's actually the normal behavior, but I'm not sure where to change it.
I tried to change things by creating a gridData but it only did worse.
The button parent is tabFolder, and the last consists of a gridlayout with two uneven columns, the spesific button is on the second column.
I tried to change things with the margins and few others, but without success.
currently all the configurations are default.
This is my button:
This is how I would like it to behave:
any help would be highly appreciated.
many thanks!
i would need some code to be sure, but it looks like you need to call tabFolder.layout(true) after changing the button text to compute the new position of your button

Using an image instead of JDialog/frame to hold swing components?

I currently have a JDialog (class that implements JDialog and is constructed like a jframe), and has 3 swing buttons placed on it. Currently I have it set, undecorated = true, to hide the outer frame. Is there any way to use my image to replace the default square frame?
This is what I aim for :
The blue square with shadow is the pre made image.
Regards
The blue square with shadow is the pre made image.
Well, the best way would be to set the background of the panel and then add a ShadowBorder to the panel. This will provide you with far more flexibility in the future as you can create many panels with different colors and reuse the same ShadowBorder instead of having to create an Image every time. I don't have an example of a ShadowBorder, but you might find one if you search the web.
Is there any way to use my image to replace the default square frame?
But if you really want to use your premade Image, then you can just:
create a JLabel and add your Image to the label as an Icon
add the label to the dialog
set the layout manager of the label
add your components to the label.

Why do I have to call expand when aligning widget inside the cell in libgdx?

I am new to libgdx. I was referring to the documentation here TableLayout-Alignment
Similar to this example, for simplicity's sake, let's say I have a nameLabel and a nameText widgets.
So when I do
table.add(nameLabel).width(100);
table.add(nameText).width(100);
I will get two widgets of of same size adjacent to each other in the middle of outside table as by-default it is centered aligned. something like this:
Now what I want to do, I want to send "nameLabel" to the extreme left and "nameText" to the extreme right.
What I am doing is that
table.add(nameLabel).width(100).left();
table.add(nameText).width(100).right();
But it won't work, until I expand both of these widgets as explained in the example above. Can anyone explain to me, why I have to expand for this alignment to work?
Calling cell.expand() make the cell expand its size to vertical or horizontal or both. Not everybody always want the cell expand after created by default.
The left and right functions only work if the cell is expanded.

How do I set Z-order for image in Swing Java

I have 3 image so I want, if I drag any image that should appear above all the other images. Which technique can use? please any idea???? By the way I am using "ImageIcon".
Thanks in advance.
If what you want to do is click on an image, lift it above the others and then drag it, consider placing them in ImageIcons and these in JLabels, and displaying them in a JLayeredPane, or a JPanel that is held in a JLayeredPane. You can then lift the clicked label onto the JLayeredPane.DRAG_LAYER while dragging, and then drop it down into the DEFAULT_LAYER (or on a JPanel that's on the DEFAULT_LAYER) when done. For an example of this, please see my code in a related question: dragging a jlabel around the screen
If I'm totally off base, sorry, but please correct my incorrect assumptions.
By the way I am using "ImageIcon".
I assume this means you are adding in image to a JLabel and are then adding the JLabel to a JPanel.
so I want, if I drag any image that should appear above all the other images
You need to add a MouseListener to the JLabel. When you click on the label then you can reset its Z-Order to 0. This will cause the label to be painted last and so it will be on top of all other labels on the panel.
So the basic code in the MouseListener would be:
panel.setComponentZOrder(label, 0);

Categories