I'm trying to make a menu like shown below. I have some items that extends CustomItem and consists of an Image and some Text. Now I want to position them as shown, but run into problems doing so - it seems only some minimal layout directives can be used in a Form. Is there a way for custom positioning using the Form class or is there another class I could use?
Make a HorizontalLayout CustomItem that aligns everything that is added to it horizontally.
Details:
Such class should have some kind of array to store all the items, and when there is a request to draw it, it should ask the width of each element inside it, do some calculations and call the items' draw method. Of course, such stuff is rather difficult. You would also have to implement the selection of these items with left/right keys...
It may be slightly better to use Canvas.
Related
I am a beginner, and i tried to find an answer but everything i found was from 2013 and earlier. I want to create a grid which you can scroll in any direction, (as a zoomed in picture), which contains items of different sizes which are generated randomly, then i want to populate them with a recycler view. I will attach an illustration, maybe you would understand it better.As you can see, the thick outline is the phone screen and whenever you scroll the view, it generates new items which are populated by a recycler view.
I thought of using Google's FlexBox Layout for generating the items but i don't really know how to create that scrollable view. I would literally pay to get this done.
I don't think you can make RecyclerView scroll in Both way. U can Create Nested RecyclerView if that is what you are looking for.
I have a tree with number of childs and i want to drag and drop these child items on a vertical panel. Right now its working fine.The only thing i want to know is can we add an image in the place of small icon which comes at the time of dragNdrop.
You need to override the newDragProxy() method of the PickupDragController in order to provide your own proxy widget (say, an image) when the drag starts.
Do note that you also need to use setBehaviorDragProxy(true) to allow dragging proxies instead of the original widgets (i.e., the original widgets will stay in place, and you simply drag a proxy of it, that you can style as you wish).
Trying to figure out if it's possible and difficultly level around the below problem as depending on such might consider other alternatives...
If I have a overall JFrame framework, can I construct various different JPanels with their associated components and actions then say pass these JPanels as args depending on user interaction so the inside of the overall JFrame/JPanel changes. I'm assuming there must be some implementation that achieves this, but having trouble find the answer.. For example I construct a JPanel, which has border layout, and the centre position will change different JPanels depending on what a user does etc.. I thought it would be a simple as create a JPanel, then passing it to a method which calls the overall Jpanel add(component, borderlayout.center) method which would change what is shown, but doesn't work like that and assumed that must only work for constructor when GUI is first constructed..
Sorry for the length, but if someone can point me in the right direction i'd be appreciated...
Removing and adding components does work as expected. You need to call revalidate() on the parent component once it's done, though.
If that doesn't work, post an SSCCE exhibiting the problem.
I am trying to write a slide show program in Java and would like to make the implementation as simple as possible.
The goal is to show a series of slides, each of which has navigation buttons, in addition to other buttons that depend on the slide's content. (A slide showing text would have a magnifyTextButtonand a slide with an image would not have this button.)
I was thinking an abstract Slide class would be appropriate, with subclasses for each slide type: TextSlide and ImageSlide. How would I implement these subclasses so that the magnifyTextButton would show up in TextSlides , and not in any other slide?
Also, my Slide class extends JFrame. Would each instance of a subclass of Slide need to construct a JFrame object if the show is designed to take place in a single window, like in PowerPoint?
How would I implement these subclasses so that the magnifyTextButton
would show up in TextSlides , and not in any other slide?
You can take a flag to decide whether to show magnify button or not. That flag will be true in TextSlides and false in other. Or you can have this button directly in TextSlide and not in other, this way no need to check anything. And processing related to magnify will only go in one class that is TextSlide.
Would each instance of a subclass of Slide need to construct a JFrame
object if the show is designed to take place in a single window, like
in PowerPoint?
In my opinion slide classed should extend JPanel. You can easily change panels on a single frame.
Some questions/answers that can help you in this:
slide effect with JPanel
Slide JPanel Content in a JForm on Java
have look at CardLayout
put Images as Icon / ImageIcon to JLabel
put JLabel contains Image as new Card
You've got a lot going on here, but let's see if I can help out.
1 : I see two options for how to lay out "magnifyTextButton." The first would be to make it a method exclusive to TextSlide. There's no reason that an ImageSlide would need to know anything about magnifyTextButton. In this format, you would then have a "draw" abstract method in your overarching abstract class (which then might be better left as an interface). I don't like this method as much as the one that follows.
Your other option is to make MagnifyTextButton a decorator. This way, you can mix and match MagnifyTextButton onto other classes with text in them (extensions of TextSlide, which you may very well want). This will give you more versatility and will require that your Slide classes need to know even less about MagnifyTextButtons!
2 : I think you want this to be a Jpanel rather than a Jframe.
I'm trying to write a scorekeeping app in Java that allows a server application to send scores to client applications. The clients will then display a list of teams, team IDs and their scores, sorted by score. Of course I could just use a swing JTable to display everything, but I want to achieve a unique effect: I want the text dynamically reorder itself every time a team moves up in the list. That is, it want to animate the text around the screen. I would also need to be able to update the contents of the labels after being added. What would be the best way to achieve this? Is there any component that allows you to add other components to it and place/move them freely?
JTable is a JComponent so you can set desired LayoutManager and add JLabels above the JTable. Then move/reorder them to achieve desired effect. See SwingWorker as well.
You could use a JTable and change the contents of the rows as teams move up. Or you could arrange a series of labels and change the text whenever you want. To change the value displayed for a JLabel you simply use the JLabel.setText("new value"); method.
I've never done this but I think you need to use a panel with a 'null' layout manager. Meaning you are responsible for absolutely positioning your elements
http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html
You would need some kind of SwingWorker or Timer running to update the gui layout. Make sure you actually make the GUI changes on the EventThread, which you can do by using SwingUtilities.invokeLater();
As alternatives to a null layout, consider letting the layout work for you using
one of the marquee effects discussed here, or
shuffling labels in a suitable layout, shown here and here.