Swing/AWT/SWT :: Trying To Get GridBayLayout To Work
Mar 20, 2015
I am trying to get the gridBagLayout function to sort my code to look like the attached image. I am having trouble figuring out how to do it or even where to start. My code can be seen below and this was as far as I could get on my own.
I have a paint program in Java where I can draw objects. The objects are stored in an arrayList. In the menubar the user can chooce "Back", which means the last item in the arrayList is removed. After that I want the program to loop through the arrayList and draw the remaining items.
My problem is that when I try to do that it will not work from the menu (menuItem2). If I instead add the code to one of the colorpanels (yellowPanel), from where the user can pick colors, it works fine.
menuItem2 uses ActionListener and yellowPanel uses MouseListener. public class PaintProgram extends JFrame implements ActionListener {
I have buttons created on a frame and then I register the listener from a controller in a controller-view relationship.
When I click the button on the face, the action never executes for some reason. I thought maybe there was a problem registering the listener but I can call the buttons doclick() method and it executes as it should. Perhaps I'm overlooking something really obvious here but I can't see it.
again, when i click the button nothing happens. but if i add the following code
btnEight.doclick()
the actionPerformed invokes in theController as I intended.
You can see the entire project on GitHub so you can see the full context. The controller class contains the listener and the view class contains the buttons.
I have a properties file with key values in it, now when I use my search box to search for a key in the properties file to check whether or not it is there - I can't get it to check and return the key value if it is theere. I've tried a few methods but keep getting a null pointer exception when it hits line 15 in the code all the time so I'm stumped at the minute.
Now my issue is I have a JTable. The first column will contain Date objects all the way to the bottom. I want the JTable to display only the month and year. I created a custom cell renderer, but it appears the cell renderer method "getTableCellRendererComponent" is never called. (I tested it using System.out.println();) Here is my code for setting the cell renderer and the contents of the first column:
MonthYearTableCellRenderer renderer = new MonthYearTableCellRenderer(); tblView.setDefaultRenderer(Date.class, renderer); for(int i = 0; i < 60; i++){ Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.add(Calendar.MONTH, i); tableModel.setValueAt(cal.getTime(), i, 0); }
The Date objects are set into the cells of column 0 correctly. The table shows the result of the "toString()" method for each cell in that column.
I have a JList<Object> in my code (it actually takes JLabels) called imageList, and I've given it a custom CellRenderer using the following code:
cellRenderer = new DefaultListCellRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
[Code] .....
However, when I click anywhere on the JList, nothing gets printed to the console, which suggests that the mousePressed() method isn't being invoked. I think it's a problem with the CellRenderer, because I have similar code elsewhere that works, the only difference being I don't use a custom CellRenderer.
The problem is as follows: I've been running java script using git bash and at one point it tells me that I need to increase heap size because apparently it takes more than 1gb to run. However although I manually increase it via control panel>programs>java nothing changes. I've been told that I need to ' figure out how to use 64bit java (and a VM that supports 64bit) in order to increase the maximum memory allocation (heap size) to something north of 2g.'
My laptop has 8GB worth of RAM (Windows 7)so it shouldn't technically have problems running anything above 1G. But there is apparently a 1GB wall But increasing the heap size to above 2G results in an error stating that VM doesn't initialize within git bash, I thought that my java is 32 bit so I downloaded a 64 bit java. Now how and if it is even possible to allocate a program to run under 64 bit java and if I should delete the other java version.
1) Instead of showing 0K 5K 10K, I would like to show the country names (A - D), with no number or tick. I figured out this one by just commenting out all the codes relating to ticks.
2) Place the country names in the center of the arch. I don't know how to do this one.
I've got a panel which an arbitrary number of text fields may be added to at run time. I've got it set up so that the window's height, and the height of the panel in which the fields appear will never exceed the height of the screen.What I don't have is a way to make the panel scroll to access the fields that are being visually truncated. I'm setting the autoscrolls on the panel to true, but when I run the program, the fields are simply truncated.
So I'm working on a project and noticed that my toString() method won't work. This is just an example of the type of code that I have in my real project. THIS IS MY MAIN CLASS
XML Code:
package trialanderror; import java.util.Scanner; public class TrialAndError { public static void main(String[] args) { Scanner keys = new Scanner(System.in); String name; String phonenumber;
I want to create a dropdown menu with contents from a database. You can see my Code in the attachment. It does not work, but why? I have a dropdown-symbol, but no contents.
I use Chrome rather than IE. Recently I got an error message when I tried to deposit a check online.
It said that I needed up get a newer version of Java than 6.10, so I downloaded 7u51.
When I tried to deposit the check again, Chrome asked if I wanted to run the app, and I said yes, but that took me back to the download link again.
I spent almost an hour with my bank experts, but they were unable to solve the problem.
When we tried it on Internet Explorer, it worked fine.
Later, I discovered that on the Java Control Panel under the Default Browser for Java, it has only IE and Mozilla, with the IE being checked and greyed out.
I'm assuming that's why the problems on Chrome, even though up until a few days ago, I was able to deposit checks using Chrome-Java.
All I am trying to do is to make a section of code execute if two strings are equal. The two strings are userId and "A001062". When I use the debugger in Eclipse, I can see the value of userId as "A001062" but whatever string comparison I try never evaluates to true. I have tried
userId=="A001602" userId.equals("A001602") "A001602.equals(userId) Assigning A001062 to a string called AAA and comparing userId to AAA
My code is as follows. I have also attached a screen shot from the Eclipse Debugger which makes me think the string comparison should succeed. I never see the debugger execute the print line nor do I see the print line on the JBOSS console.
String userId = StringUtils.trim(nextLine[HR_USER_ID]); String AAA="A001062"; if (userId.intern().equals(AAA.intern())) {System.out.print("MKP1: " + userId+"-"+managerId);} if (userId.compareTo("DTS0428")==0) {System.out.print("MKP2: " + userId+"-"+managerId);}
I have being trying to figure out why my string doesn't work as a passcode and I can't seem to figure out why.
import java.util.*; public class Login { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Hello there, please state your name"); String userName = in.nextLine();
I have a code issue and I have a below question for the same.Assuming data[] is of type byte[], is the below statement in java -
while((data[p++] & 0x80) == 0x80);
same as -
while ( (data[p] & 0x80) == 0x80 ) { p++; }
I tried with do { p++; } while ( (data[p] & 0x80) == 0x80 ); That also doesn't seem to be the same thing. I am not putting code around this but essentially if I make this change for not using data[p++] code stops working!
I have a simple applet that doesn't stray outside the sandbox. It used to work fine before Java 7 but now it craps out with security warnings. It does nothing but play a game, it doesn't even save the state of the game. This is the applet, it's a very simple chess program.
The warnings and popups I'm getting are: activate javaTM platform SE 7U?allow now?activation blocked by security settings - I never changed any security settings and as I said, this applet stays firmly in the sandbox so I can't see what the issue is.Viewing the java error window I see
Java Plug-in 10.51.2.13 Using JRE version 1.7.0_51-b13 Java HotSpot(TM) Client VM User home directory = C:UsersMike ---------------------------------------------------- c: clear console window f: finalize objects on finalization queue g: garbage collect h: display this help message l: dump classloader list m: print memory usage o: trigger logging
[code]....
why it shows the C:UsersMike directory in the above listing, there is no access to files etc.The applet plays fine if I run it in appletviewer.What do I need to do to make this simply work in anyone's browser? I have a similar problem with a (rather funky) Connect 4 program I wrote. It worked fine for years and then just stopped with the Java 7.
I can't get Relative paths to work. I have created the class.dat file and I can't get java to recognize it. I am using Eclipse as an IDE. Was wondering if I could get Eclipse to recognize it. I tried with a .txt file as well and couldn't get that to work.
import java.io.*; public class ReadBytes { public static void main(String[] args) { try { FileInputStream file = new FileInputStream("class.dat");