I have a swing form in my program and I used a panel which uses title border as you see in the picture:
I want to put the title ( marked with red oval ) of title border to the right but I don't want to use applyComponentOrientation function because it reorders all my element in the ?panel, is there any way to do that ?
The place to start is by reading the TitledBorder API.
There are methods like:
setTitleJustification(...);
setTitlePosition(...);
to help you position the title. I'll let you read the API to find the appropriate values for your requirements.
Try this one it has justification method as #camickr said.
setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(10,10,10,10,Color.BLACK),"Title",TitledBorder.RIGHT,TitledBorder.TOP));
Related
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.
So, I have a Calendar solution for my employers where I am using a custom look and feel (Synthetica) and each cell in the table holds a JPanel with a list of buttons and a PAGE_AXIS BoxLayout. I am trying to reduce the gaps between each button so that they abut each other, and I've tried setting the borders to null except that destroys the button appearance. I have used the following (as recommended by Oracle to view the actual size of the components) code;
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.red),
getBorder()));
And this is what I get;
Setting the margin does not work with whatever border version the buttons are using. So, is there any way to find the current border that it's using? So that I can set that border's insets manually, or something like that. Basically, I need the buttons to abut each other. Any ideas?
Clarification: I want the button's themselves to stay the same size, but I want the white space around them (highlighted inside of the red borders) to be gone,
Several possibilities should be considered:
Manipulate the button's bound properties: setBorderPainted(false), et al., as suggested here.
See if a suitable sizeVariant is available, as shown here.
Use a custom UI delegate based on BasicButtonUI, as shown here and here.
I tried to get the Synthetica L&F to have a look but seems as though you have to create an account which I did not want to do. Anyways, a quick look around the website and I found a page which indicates how you can see and configure some of the values set in the L&F. Might be worth having a look there.
http://www.jyloo.com/synthetica/customize/
I'd like to change the color of the java titlebar and add some text to the ends and the middle.
The previous coder used setUndecorated(false) and a JPanel to achieve this effect but I am trying to change this to modify the actual title bar because the panel solution is an issue with menus and focus.
tl;dr Want to change the color of the titlebar and set text in the middle and one the ends.
I think you can change the title bar color with the method described here: http://www.coderanch.com/t/346141/GUI/java/set-JFrame-titlebar-color
Changing the text should be possible via setTitle(). You can call this method as many times as you want throughout the life of the application to change the title text on the fly.
In C#, to make the tabs go from right to left, I set RightToLeft to Yes and RightToLeftFormat to true. How do I do the same thing in Java? How do I set a JTabbedPane's tabs to display from right to left? Please see the image link below to see what I mean by displaying tabs right to left.
http://lh4.ggpht.com/_1bcR6vegNNc/TPDRekNVqWI/AAAAAAAAAB8/TwCqgajEuoI/s640/AdminDashboard.jpg
I assume by "tabbed pane" you are referring to javax.swing.JTabbedPane.
To answer your question: AFAIK there is no easy way to do what you want. The BasicTabbedPaneUI(or the TabbedPaneUI which is defined by your application look and feel) which is responsible for painting the tab area of the tabbed pane would require some changes to be able to do what you need.
If you do not have the time to write your own UI, you could look for solutions in the web. I doubt that there would be a ready to use solution to your question though, but then again, who knows?
Hope this helps you a bit.
Then i'm refer from "How to Use Tabbed Panes" to create a new project based by JTabbedPane component...
It's enough to use "setComponentOrientation" method to change orentation of JTabbedPane.
link text
Trying to build a GUI application in Java/Swing. I'm mainly used to "painting" GUIs on the Windows side with tools like VB (or to be more precise, Gupta SQLWindows... wonder how many people know what that is ;-)).
I can't find an equivalent of a Group Box in Swing...
With a group box, you have a square box (usually with a title) around a couple of related widgets. One example is a group box around a few radio buttons (with the title explaining what the radio buttons are about, e.g. Group Box entitled "Sex" with "Male" and "Female" radio buttons).
I've searched around a bit... the only way I found was to add a sub-pane, set the border on the sub-pane and then add all the widgets in the "group" to the sub-pane. Is there a more elegant way to do that?
Create a JPanel, and add your radiobuttons to it. Don't forget to set the layout of the JPanel to something appropriate.
Then call panel.setBorder(BorderFactory.createTitledBorder(name));
Others have already commetned about JPanel and using a TitledBorder, that's fine.
However, when playing with Swing LayoutManagers, you may find it annoying that components in different JPanels cannot align correctly (each panel has its own LayoutManager).
For this reason, it is a good practice (check "JGoodies" on the web for more details) in Swing GUIs to NOT use TitledBorders but rather separate groups of components in a JPanel by a JLabel followed by a horizontal JSeparator.
Ref. "First Aid for Swing"
A Group box is just a set of 'logically grouped widgets'.
This in the swing world is a JPanel.
Add your widgets to a JPanel.
Set its border type to 'Titled Border' and give the title, same as the name of the VB6 'frame'.
Voila. You have your group box.
Here's a quote from the JRadioButton javadocs since you brought up radio buttons.
An implementation of a radio button -- an item that can be selected or deselected, and which displays its state to the user. Used with a ButtonGroup object to create a group of buttons in which only one button at a time can be selected. (Create a ButtonGroup object and use its add method to include the JRadioButton objects in the group.)
Note: The ButtonGroup object is a logical grouping -- not a physical grouping. To create a button panel, you should still create a JPanel or similar container-object and add a Border to it to set it off from surrounding components.
Not AFAIK, at least not with standard swing widgets.
In VB you have a group widget, which is essentially a panel + border.
In Swing you have a JPanel which is the container widget, and you create and set a border object on it only if you need one. One can argue that in a way that is more elegant since you don't pay for something you don't use (e.g., border)
As David Koelle mentioned about setting up border through java code, you can also achieve similar result in designer mode.
I'm responding based on the Uri's comment which explaind what the OP meant by Group Box:
Uri: I think he means the control group you see in many dialog boxes, where you have a square around a bunch of widgets such as radio buttons, for example.
As far as I know, every JComponent can set a border for itself, so you don't need a second panel.