There are multiple ways but I recommend these lines of code:
GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
Frame fr= new Frame();
fr.setMaximizedBounds(e.getMaximumWindowBounds());
fr.setExtendedState(main.getExtendedState() | JFrame.MAXIMIZED_BOTH);
fr.setVisible(true);
The code above will maximize your frame/window without hiding the taskbar (at the bottom part) in your screen except if you used undecorated frame. Any maximizing will hide your taskbar. This is according to my own experience but if you found ways to against it, please post it as a comment. Thanks :)
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Wednesday, May 4, 2011
Sunday, August 22, 2010
How to remove events not used in NETBEANS
You might want to remove some events that are not used anymore in your NetBeans file project. You cannot just delete it from the code editor because NetBeans lock it, indicated by the gray color of the line of codes.
Here's how to remove those unused codes:
1. Go to the GUI builder, the Design view of your file.
2. Right click and select Properties. The default open tab is the Properties list. Select the Events tab.
3. You would see events list and what handlers these events are associated.
4. Choose the event you'd like to delete by selecting the [...] button.
5. A new dialog will pop up. Select the handler then click Remove button.
Here's how to remove those unused codes:
1. Go to the GUI builder, the Design view of your file.
2. Right click and select Properties. The default open tab is the Properties list. Select the Events tab.
3. You would see events list and what handlers these events are associated.
4. Choose the event you'd like to delete by selecting the [...] button.
5. A new dialog will pop up. Select the handler then click Remove button.
Thursday, July 15, 2010
How to disable edit cell in JTable (especially in NetBeans)
Put this in your code:
where table is the name of your JTable.
For NetBeans users:
1. select the table GUI, right click, select Customize Code
2. Your code should look like this:
table = new javax.swing.JTable(){
public boolean isCellEditable(int rowIndex, int colIndex) {
return false; //Disallow the editing of any cell
}
};
where table is the name of your JTable.
For NetBeans users:
1. select the table GUI, right click, select Customize Code
2. Your code should look like this:
How to Select All textfield/ password field Java
--start--
Sample code:
int i = textfield.getText().length();
textfield.setSelectionStart(0);
textfield.setSelectionEnd(i);
Put this in the action or wherever you want it. Replace textfield variable to the name of your textfield. I'm not sure but this might work for JTextArea and JTextPane too.
--end---
Sample code:
int i = textfield.getText().length();
textfield.setSelectionStart(0);
textfield.setSelectionEnd(i);
Put this in the action or wherever you want it. Replace textfield variable to the name of your textfield. I'm not sure but this might work for JTextArea and JTextPane too.
--end---
Friday, May 14, 2010
How to remove JTextArea line around rectangle (border)
code:
In NetBeans:
1. Click the text area
2. Go to Properties
3. Scroll to Other Properties
4. Go to border then select (No Border)
5. Put this in your constructor:
textarea.setBorder(null);
In NetBeans:
1. Click the text area
2. Go to Properties
3. Scroll to Other Properties
4. Go to border then select (No Border)
5. Put this in your constructor:
jScrollPane1.setBorder(null);
This is because NetBeans automatically creates scrollpane to your text area and its border is visible until you set it to null.
6. Run the file to see the result.
It worked for me just fine :)
Thursday, May 13, 2010
How to resize ImageIcon - Java
Please make reading a habit :)
This was my problem before. After days of searching, I combined the codes of my search items and came up with this:
-- start of function. I put it inside a function --
//gets the directory of the file
//this means that the file name is where the directory is plus the folder pictures plus the filename
//which is hold by the string named idnumber
idnumber = "CO00001";
dir_pic = System.getProperty("user.dir");
dir_pic = dir_pic+"\\Pictures\\"+idnumber+".jpg";
//you could simply put the path of the image in dir_pic variable
//We should have an image first.
//For me, I open the image from my directory
File file = new File(dir_pic);
image = ImageIO.read(file); //reads the image
//this sets the image to an Image Icon
ImageIcon icon = new ImageIcon(image);
ImageIcon icon = new ImageIcon(image);
//we start to scale here
//first get the image from ImageIcon
Image img = icon.getImage();
Image img = icon.getImage();
//then scale it; I scaled it to 120x120
//please check the documentation for parameter listing if u dont want SCALE_SMOOTH
Image newimg = img.getScaledInstance(120, 120,java.awt.Image.SCALE_SMOOTH);
newIcon = new ImageIcon(newimg); //we now have new icon - scaled by 120x120
//I made a JLabel named label and put the image there
label = new JLabel(new ImageIcon(newimg));
//then put the label to a square panel
picpanel.add(label);
label.setBounds(2, 2, 115, 105); //change the bounds according to your design
--- end of function ---
For questions, post a comment to this post... :)
Thursday, February 11, 2010
My case of: Jasper Report won't run
___________________________________________________________
We have a system that would print student profile, on our implementation we used the jar file to execute the system for our demo. Then we found out that one function is not working.
Case: when I clicked the JButton that triggers Jasper reporting, the preview of the document wont show up. It appears in other computers but some other pc units wont, too.
After how many trials, debugging and troubleshooting, we decided to install the IDE in the deployment PC. Then we saw the bug, at last.
Bug: No FONT installed. We used a font in the development environment where that font is not installed in the PC of the deployment environment. So that what kept our project delayed for a week. lol.
___________________________________________________________
Thursday, December 10, 2009
How to Check if Radio Button is Selected or Deselected in Java
***
I can't seem to find an easier way to do this, or perhaps this is the only way since RadioButton depends on the action listener. Here's my code:
private void radioButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
count++;
int ans = count%2;
if( ans == 0){
//radio button is deselected
}else{
//radio button is selected
}
}
***
Monday, November 23, 2009
How to Add Formatted Text Field in Netbeans: Limit the Input in Java Text Field
---
Formatted text field is a feature in Java programming that lets you control the input in your JTextFields.
In Netbeans IDE, you cannot just edit the codes anywhere you like it if the GUI is generated by the IDE. This may mean that putting your formatting code would take you some time by overriding the class, function, etc (That's how you usually customize Netbeans - generated codes). However, there's a shorter way to do that, follow these steps:




1. Right click on the JFormattedTextField and select Customize Code
Labels:
formatting,
Java,
JFormattedTextField,
Netbeans,
textfield





