Assume that the back is using a JTextPane, and I would like to implement a view with a label. But how can I implement the view in Java? is that something like UIView on iPhone on the Java Swing? Thanks.
If I understand correctly, you would like to display a JLabel on top of a JTextPane. If so, use a JLayeredPane.
Read the Swing tutorial on layered panes to learn how to use them.
Are you looking for something like this?
See Twinkle
There's nothing special about this; just pack an extra JPanel along the bottom of your window, and put a JLabel into it; set the text of the JLabel as needed.
Related
I'm new to Java and I would like to know how to position an image within a JTextPane. Is it possible? Is there any other methods for positioning an image in a JLabel?
The gridBagLayout can be used to position components within a JFrame.
Take a look here: http://docs.oracle.com/javase/7/docs/api/java/awt/GridBagLayout.html
I usually use gridLayout,it is less flexible, but easy to use for simple layouts.
You can create a JLabel for the image, call setBounds() for the image and call jTextPaneInstance.add(theImageLabel).Or you can specify any desired LayoutManager for the jTextPaneInstance and just add the label with appropriate constraint.
If you mean something like text flow around the image it's much much more difficult to implement but also possible (depends on EditorKit you use there).
I'm writing a simple text editor in java, I have done it before now I have some new ideas, normally when I put in a JTextArea when I have a FlowLayout on my JFrame it will fill what is left of the JFrame. However this time it's not. Could someone help me out trying to get it to fill the rest of my JFrame? Thanks!
http://docs.oracle.com/javase/tutorial/uiswing/layout/layoutlist.html
Java does have various layouts. For making dynamic body changes you have to learn more flexible layouts like grid or grid bag layout. Hope this help.
Is there a way to resize a control, a JTextfield for example, at runtime in java? I want my textfield to have the resize cursors (just like when you point your cursor on the corner of a window) and will be able to resize on runtime. Ive read on the internet that vb6 and C# have those capabilities, is there anything for java? A sample code or a link to a good tutorial will be very much appreciated. Thank you.
It sounds like you are trying to implement a component editor, such as the GUI editors available in popular programing IDEs. The essential feature is a handle, a graphical object that can be selected and dragged to change the geometry. GraphPanel is a simple example of an object drawing program that illustrates many of the required techniques.
That depends on the Layout of the JTextField's container. A good tutorial is available at http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
For a quick and cheap solution you could use a JSplitPane component, with the JTextField to be resized in the left side, and an empty JPanel in the right side. By default a JSplitPane is decorated with a border and a divider, but you can remove these by setting an empty border.
It is to support image dragging. How to find if an image is clicked in JApplet?
I'm sure there is an easy way to do this, but I've looked everywhere and cannot seem to find it.
Options:
Use a JLabel to hold the image, and give it a MouseListener. Simple.
Or create a JButtton and use the Image as the button's ImageIcon. Probably simpler.
See the Drag and Drop and Data Transfer lesson of the tutorial.
If the purpose of the dragging is to change the order in a slideshow or similar, look to a JList. See setDragEnabled(true) & How to Use Lists for more details.
For the display component, I would recommend a JLabel as suggested by #Hover. JList uses a JLabel as the rendering component by default.
I have a JFrame in which i have to insert JLabels, textfields and JButtons. I am able to these but how can i adjust them to the required position, i want to add one label and textfield in one row and then nxt label and textfield in the next row but they are coming in the same horizontal line. i have used flowLayout with the JFrame. please tell me how to adjust them accordingly. thanks
The key to distributing components in a Container in Swing is the Layout Manager. There are various types out there. To do what you are looking for, you might want to consider the GridLayout. It is pretty easy to set up. You first need to create the layout. The following will create a two columned layout with as many rows as you provide:
GridLayout gl = new GridLayout(0,2);
Then you apply it to your panel:
JPanel panel = new JPanel(gl);
Then you add your items:
panel.add(textfield1);
panel.add(button1);
panel.add(textfield2);
panel.add(button2);
The GridLayout will handle moving from row to row after you fill in the columns with components.
had a look at gridbaglayout? Should serve your purpose.
A GridLayout may be what you want, or a combination of a GridLayout and a FlowLayout. Look at the LayoutManager tutorial to get a better idea of when and how to use and combine the various layout managers.
You need to study the various types of layouts swing provides.
Also you can have a look at FormLayout,provide by JGoodies. I prefer to use this than swing layouts as i find it easy to code and less lines of code
You are using the default Swing Layout Manager. If you want different behaviour (which is very reasonable) then you need to use another LayoutManager. Several exists both from Sun and "out there".
In order for you to be able to choose, you need to know how they work. I can strongly recommend using the Java Tutorial for this:
http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
Let us know if you need more than provided by e.g. nested BorderLayout's or TableLayout.
If you want to be able to position the UI elements in your application (nearly) absolutely, consider using a decent GUI builder like Matisse in NetBeans or Swing UI Designer in IntelliJ IDEA.