I'm making a Unicode translator in Java. I did all hard parts, but now I want to add a resizable, relocatable image to the textpane. The user must be able to resize image with its corners and drag & drop the image within the textpane where he likes. (like Microsoft Word or Photoshop)
Something like this:
I tried the Styled Document properties. But I couldn't find way except inserting only an ImageIcon.
May be a better choice would be not to use textPane.
If you have an custom editable label, that can be edited by double clicking on it to show a text box to edit the contents, and change the text of the label when enter key is pressed.
Also give a shot of JDesktoppane, JLayeredPane, and check what components can be added to it.
try this
http://mgeisler.net/downloads/browser/src/ImageBox.java.html
try loading the image inside a JLabel component in JFC Swing.
Otherwise try some other non editable components in the same technology with resizable property.
try this http://sourceforge.net/projects/ird/
the iRD is a component for Resize and move(drag&drop) compoennts on runtime in java.
Related
I was searching in the past days for a possibility to insert more options into the JFileChooser, beside the "normal" name of the file and extension filter.
Example:
I have to save EEPROM datafields to the PC in certain text filetypes. The EEPROM contains hex values. I want to be able to choose how I save these hex values: in hex, as they are, or directly in ASCII.
I want to get something similar like in Word >=2010 when saving a file as *pdf. There are extra options you can set.
Here is a picture I made: What I want
Thank You!
It seems to me that you can put that information in the filter, however, remember that the JFileChooser is a component that can be placed in your own JDialog.
So you can create a JDialog with, say a BorderLayout, with a JFileChooser at the "center", and a JPanel at the "south". You can add whatever controls you want on the JPanel.
You can either keep the control buttons (Open, Save, Cancel) on the JFileChooser, or hide them by using:
fileChooser.setControlButtonsAreShown(false);
in which case, you would need to provide your own buttons on the JPanel.
An issue with this technique, is the misalignment of the components in the JPanel with those of the JFileChooser.
I want to build a chat room whit java swing.
I want to have a component to show text, image, gif and emoji.
please help me to select a good component.
In first I choose JtextPane for this.Is it good?
In first I choose JtextPane for this.Is it good?
Yes, I would use a JTextPane, with normal text (not HTML). With a JTextPane you can:
text with attributes.
align text to the right/left of the text pane
display icons using the insertIcon(...) method.
Read the section from the Swing tutorial on Text Component Features for some examples that use attributes when adding text.
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 am trying to recreate the Skype handles instant messaging using Swing components. I am using JList with a custom ListCellRenderer to render each cell in the list. The ListCellRenderer extends a JPanel, the JPanel simply contains a label (where I will put the username) and a JTextArea which is where the users' messages will go. The JTextArea is what Im having problems with.
Here's an image of what I have a the moment -
Ive removed the scrollpane that automatically comes with the textarea in netbeans.
I am showing the Navigator, the Design view and the actual program (the list has two elements) in this image.
The the text in textarea is actually much longer than in this image but it is not word wrapping. I have set lineWrap and wrapStyleWord to true in the properties box for this textarea but it doesn't seem to take any effect. I then tried to set maximum size using the properties box and that doesn't have any effect either.
Is there any way to control the padding/margins around components with netbeans gui designer. The automatic placement it gives me for spacing between components is either several pixels too small or two large. I need exact placement on the list's cell components.
For reference here is how skype's convesation panel looks (ive added in the red "Brian cs"'s as thats how I will be doing it in my program). As you can see the sentences wrap and there is an appropriate amount of space between cells. So anyone know how to achieve this using Swing?
The JTextarea is not the problem. The JList sets the heigth for each row. See JList.setFixedCellHeigth or setPrototypeCellValue
I am trying to change the font of the text in a textarea in Swing. Which listener should I use on textarea to trigger an action that lets the program initiate the font code.
All the examples have all the swing in the same class which lets you access the textarea directly, but I have multiple classes; I know I can pass the textarea in and in and in, but this is sloppy.
I just cannot figure out which listener to initiate.
I am trying to change the font of the
text in a textarea in Swing.
Well a JTextArea can only have a single Font, so if you want to change the Font you would have some other component, maybe a "Change Font" button that you would click. In this case you would add an ActionListener to the button to change the actual Font of the text area.
If you actually need to change the Font on selected pieces of text, then you also can't do this with a JTextArea. You would need to use a JTextPane. Read the JTextPane API and follow the link to the Swing tutorial on "Text Component Features" for an example of changing attributes on selected text. In this cause you use Actions provided by the editor kit.
So basically you need to read the Swing tutorial to find out the basics of using Swing components.
If you're listening to the textarea, then it would depend on how many different ways you want the user to be able to change the font of what they are typing.
You could use MouseListener if you want them to be able to change the font on right click/etc... or a KeyListener if you want to listen for a series of keys.