Swing/AWT/SWT :: How To Change CheckBoxTree From FileSystemView To File
Mar 5, 2015
I am trying to use a CheckBoxTree that has been already created here: [URL] .... The problem which this JTree is that is uses FileSystemView for the root directory and as far as I know it does not set any root directory.
So I want to have the ability to give it a root directory. for example: new File("C:Temp") So when the tree appears , it lists files and folders in the provided address, and not the entire system.
The code is available in the provided GitHub. I tried to replace all FileSystemView fileSystemView in constrictors and bodies with File file to make it working. It worked but ended up with errors such as not showing the file icons.
How to modify it correctly or if there is any better way to convert FileSystemView to File?
I have a strange problems. Perhaps some of you already have had this problem before.
I have method which is suppose to check if the itemstate has changed. It ONLY works ONCE?
Thereafter, it does not matter how many times I changed the selection of the ComboBox.
Basically I have two Comboboxes.
1. If Combobox 1 is selected (e.g. Dogs, Cats) 2. Then get information from what ever the item from ComboBox 1 is selected, and display on ComboBox 2. (Dog Name, Cat Name etc)
E.g.
So If I selected Dogs on Combobox 1 Then display the Dog Names on Combobox 2. If I then change and select Cats on Combobox 1, then display Cat Names on ComboBox 2.
I am quite familiar with using JOptionPane and its various displayXDialog() methods and reasonably familiar with changing fonts.
I have a JOptionPane.displayMessageDialog() that is working fine but I decided to make the font larger.
I found an example from which I coded:
Font font = UIManager.getFont("OptionPane.font"); UIManager.put("OptionPane.font", new Font(font.getName(), font.getStyle(), 24)); font = UIManager.getFont("OptionPane.font"); JOptionPane.showMessageDialog(this, "Welcome to Mover", "About Mover", -1); // no icon
After the UIManager.getFont() call after the UIManager.put() call, font shows the new font size of 24, but the showMessageDialog() dialog still has the default font.
And yes I understand that, when this works, it will affect every JOptionPane in my program.
I also tried:
Font font = UIManager.getFont("OptionPane.font"); JOptionPane message = new JOptionPane("Welcome to Mover", JOptionPane.INFORMATION_MESSAGE); JDialog dlg = message.createDialog("About Mover");
[Code] ....
This gave me a dialog with the default font and an unwanted icon.
So I tried
// both Font font = UIManager.getFont("Dialog.font"); // and Font font = UIManager.getFont("JDialog.font");
and planned to use that font in my setFont() call but font was null.
I am trying to write an application where if you click and hold down on 1 button and move the mouse to another button and release the text on the 2 buttons should be switched around.I have a print line so I can se the text are supposed to get switched around but it is just not happening in the GUI.
I attached all my code in case the flaw was to find somewhere else in the code, but the functionality I am working on is the lines 76 to 121.
I am relatively new to java. . I cannot...(actually do not know) how to change the actionlistener (actionPerformed) after the second click in an array of JButtons. This is how the program performs right now.
On the 1st click on the grid, the border of the button clicked will change to 'blue' and another button will change its boarder to 'red'. on the next click the same action is performed.
What I need is to change action when the 'red' bordered button is clicked, lets say change the color of the buttons from the 'red' to the 'blue' buttons.(x 3 buttons).
The logic about how to perform the final result I think I can do on my own but my problem is how to change the action when the red bordered button is clicked.
So, I have a game. I would like to make a game where you press "start" and THEN it starts. Also, I want to have collision with triangles, not just squares. The way I handle collision right now is with if statements, if the object is within the other, game over.How would I do collision with triangles? Lastly, how do I set a high score? how to change fonts and font size in swing?
I made a game but i didn't add imports, i have been told i need to have imports and it needs to be in a normal swing format or it will not pass . How to change my code to swing format?
My code is
public class TextTwist extends javax.swing.JFrame implements java.awt.event.ActionListener { // hard code, should be picked from a Problem class private String[] letters = {"F","O","C","I","E","F"}; // hard code, should be picked from a Problem class private String[] solutions = {"ICE","OFF","FOE","FOCI","OFFICE"};
[Code] ....
How do i get the program to move on to the next one String?
I'm using a jpanel with an 8 by 8 grid layout of jlabels to which I'm adding images to represent a chess board. At first, I was using the ImageIcon class to initialize my icons, but as soon as I added these icons to the labels, the labels no longer changed size with the window (which I want to happen). URL...
So I copied in the class, and initialized a different set of icons using the stretch icon class (specifically, the method that allows you to initialize a stretch icon from a filename), however, when I use these stretch icons, the result is the same. Is something wrong with the class, or with my implimentation of it, and how would I fix this?
i just started java and I'm trying to change the JLabel text by clicking on the JButton however it isn't working,
import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JLabel; public class BorderLayoutJFrame extends JFrame { public static final int WIDTH = 400; public static final int HEIGHT = 400;
I'm dealing with, change the content pane color of jFilechooser. Color has been changed but the problem is when I open the subdirectory leads errors; Note : It also trigger error when I set default directory; like chooser.setCurrentDirectory(file);
The following error is the result:
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException at javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(MetalFileChooserUI.java:912) at javax.swing.SwingUtilities.layoutCompoundLabelImpl(SwingUtilities.java:961) at javax.swing.SwingUtilities.layoutCompoundLabel(SwingUtilities.java:888) at javax.swing.plaf.basic.BasicLabelUI.layoutCL(BasicLabelUI.java:94) at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:239)
I'm using a jpanel with an 8 by 8 grid layout of jlabels to which I'm adding images to represent a chess board. At first, I was using the ImageIcon class to initialize my icons, but as soon as I added these icons to the labels, the labels no longer changed size with the window (which I want to happen). Someone suggested to me to use this custom stretch icon class, found here:
[URL] ....
So I copied in the class, and initialized a different set of icons using the stretch icon class (specifically, the method that allows you to initialize a stretch icon from a filename), however, when I use these stretch icons, the result is the same. Is something wrong with the class, or with my implementation of it, and how would I fix this?
I'd like to change the text on the two buttons which I have in my Dialog Box, how should I do this?
Also, when I click the X Button in the top right of the Dialog Box, nothing happens, and the program only stops when I end it in jGrasp. How do I make this button close the program when clicked on?
import javax.swing.*; import java.util.Random; public class SwingInputExample { public static void main(String args[]) {
This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.
public void actionPerformed (ActionEvent e){ if (e.getSource ==add) { if (text.getText().equalsIgnoreCase("Exam Schedule")){ link1.setText(text.getText()); link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
I'm trying to create a chess program in java swing, and for the board I'm using an 8 by 8 array of jlabels stuck inside a jpanel with a grid layout. I would like the board to change size when the window changes size, and the grid layout accomplishes this succesfully, until I add the actual icons to the jlabels. Then the board just stays a fixed size. Someone suggested I use their "Stretch Icon" class, found here:[URL] ...., so I tried initializing the icons using one of the constructors in the class (the one that takes an image name and a boolean value for whether or not you want the resisizing to be proportionate (to maintain the aspect ratio)). However, the same thing happened. The board appears, but it does not resisize. To attempt to fix this problem, I tried simplifying my code, reducing the program to two jlabels within the jpanel, for which I then tried to set the image in the same way. Here is my simplified code:
I'm working on a spreadsheet-like table and I was able to set it so that it would highlight the first cell in the relevant row(titled 1,2,3.. etc) when a cell is clicked. (Just like in MS Excel - preview attached) Now I want to do the same to the column header(i.e. A,B,C,D....etc) . How can I do it?
private void formWindowOpened(java.awt.event.WindowEvent evt) { setLocationRelativeTo(null); int rowNum = sheet.getRowCount(); for(int i=0; i<rowNum; i++){ sheet.setValueAt(i+1, i, 0);