As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Look at image below and notice JRadioButtonMenuItem do not extends JRadioButton, even not JToggleButton. My guess is that they repeat code. :P Or perhaps they have a intermediary class inside these toggle component?
The thing is that Java does not support multiple inheritance, otherwise you could have considered having JRadioButtonMenuItem extending both JMenuItem and JRadioButton (although it is not clear if it would have been a good implementation choice).
So this means that you have to choose one or the other, in this case, the choice has been made to extend JMenuItem.
Now, if you take a look, you see that JMenuItem and JRadioButton have a common ancestor which is AbstractButton which actually encapsulates a ButtonModel where everything related to the current state of a button is stored (armed, selected, etc...).
In the case of a JRadioButtonMenuItem it uses a ToggleButtonModel and so here you have how the same model is shared by JRadioButton and JRadioButtonMenutItem.
Regarding the view, this is all delegated into the BasicRadioButtonMenuItemUI and especially more into BasicMenuItemUI (which is the parent of BasicRadioButtonMenuItemUI). Eventually it relies on the current Look-and-feel to provide the different icons, styles, borders, fonts, etc...
And this is how the whole thing goes.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
i want to start coding a game project which is called "Risk" and my first aim is build the map correctly. So logically, each territory should be a JButton but JButton's are rectangular oriented. Moreover, i know that every territory should be a component so i can use mouse event listeners for each of them. well my question is
should i try to draw each territory with using coordinates, lines, shapes etc ? or
is there any way to draw and combine each territory regularly ?
On the other hand, this is the link for the map of the game.
Map of Risk
try to make fixed territories, so you mustn't have headaches with resizing your actual territory, only change the color of the territory you occupied recently, like in Dune2 was, if you know that game. And I think, definitively you should, and put that jbutton under the numbers on your map (or what will be definitively better, if you replace numbers with territory name and you'd put that button under that). I hope, my answer answered your doubts :)
I feel like it's going to be a lot of work. The easy way out would be to just put JButtons under the numbers.
If you still feel inclined to make irregularly shaped clickable areas, I suggest creating instances of Polygon (java.awt) for each country. They are made using arrays of x and y points that define the corners. Conveniently enough, there is a Polygon.contains(x, y) method that lets you know if (x, y) is in your polygon. If you use a larger JPanel that covers the entire map and get the mouse location relative to the JPanel, you can notify each country whether or not the mouse is inside it.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm curious as to what each of the components are on BitDefender's GUI. I've provided a picture in hopes that some could explain how this type of GUI was accomplished.
I'm not wanting to re-create the GUI, I'm just wanting to know if someone can name the components and perhaps tell me what they did to get that look and feel?
Thank you to anyone who spends the time explaining.
Swing's GUI framework is very flexible, most likely the arbitrary components such as the big round button at the top were simply custom components with a nice looking skin.
The rest just look to be standard components with custom skins, for example the big rectangles housing the antivirus/firewall/antispam/update are just jpanels or even unselectable buttons. There are many ways to make something look how you want, and there's never one standard way to do it.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have a main class in java which has no attributes and methods. It only contains a main method which calls methods of other classes.
How can I show this class in a UML class diagram?
You should use Association to show this relationship. Association is shown by just connecting two class with a straight line.
If you also want to show the direction of association then you can use directed arrow.
You should question whether you need that class. It doesn't sound like it is performing as an object, instead its a superclass with no meaning within an OO context (ie: it has no meaning within your subject matter, holds no state and performs no actions aside from the main method).
Nothing necessarily wrong with that, but its not considered good practise. I would consider merging that main method into another class that has a meaning within your application.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Friends!
I want to create a simple schedule event calendar like this one
Question: What can i use in Swing/AWT hiearchy in order to have such flexible grid.
P.S I was trying to do some solution in JTable direction with Custom CellRenderers but it was ugly. Maybe it can be something like JPanel-in-JPanel solution? What do you think?
This is not a simple solution and you have any number of options...
Because the content can expand over multiple rows, JTable isn't really a viable solution (there's probably any number of ways to do it, but each will become more complicated over time...and any solution I've seen doesn't take into account the current Look and Feel).
But if you're interested, you could take a look at
spantable (haven't used)
JTable Examples (haven't used)
You other choice would be to create a custom component capable of rendering the data model.
I, personally, would focus on an individual column, allowing it to be it's panel. With a custom layout manager, you could layout additional components based on the requirements of the data model.
Once you have that figured out, you would be able to expand the concept to allow for multiple rows.
This allows you greater flexibility in how the individual components are laid out and rendered, but is quite complex.
I would take a look at How to use Scroll Panes so you can see how row and column headers work ;)
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What is the use of Container in Swing?
A Swing Container is a component that holds or wraps-up other components. It aids with grouping related components together in the GUI. There are a lot of resources on the web that explain how to use Containers.
http://java.sun.com/products/jfc/tsc/articles/containers/index.html
http://oreilly.com/catalog/jswing/chapter/ch08.pdf
A container in Swing is something that holds other components.
A container is responsible to displaying the components according to your layout.
If a button is placed on the top left corner, every time the window is re-sized, the button will still be on the top left corner. This is because the container is containing the button and at the same time containing its layout position. That is why it's container.setLayout()
and container.add()
In Java Swing, a lot of components can be a container. A JButton can be a container, and so can a JLabel.
JPanel is also a container, and anything that extends those three can also be a container.
Well ... Containers are used to contain other widgets, and to help arrange them in a way that suits the design of the UI.
For instance, JPanel is a general-purpose container. Together with a LayoutManager, you can get many different layouts of widgets.
Container can has other compoments or container. it can be three level.
top level .such as JFrame, JDialog,JApplet.these containers can't be contained.
immediate container ,such as Jpanel we ofen use
low level. So this is what we know as low level components.