Unable to use Sea Glass Look and Feel together with JFreeChart - java

When i used Sea-glass look and feel with JFreechart, the chart appreared normally but Sea-Glass didn't change the look and feel at all, although when sea-glass was used without Jfreechart, it worked.
So, what could be the reason?
public static void main(String[] args) throws Exception{
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
JFreeChart chart = chart_producer(url) //my own static method to make the chart//
JFrame frame = new JFrame();
JPanel panel = new JPanel();
ChartPanel chartPanel = new ChartPanel(chart);
//chartPanel.setPopupMenu(null);
//chartPanel.setMouseZoomable(false);
panel.add(chartPanel);
frame.add(panel);
frame.pack();
frame.setVisible(true);
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}
);
}

Note that JFreeChart is not a JComponent. It does not have a UI delegate to change. Alternatively, applying a ChartTheme may be effective.
Addendum: Although a chart is not a component, it may be added to a ChartPanel as part of an arbitrary L&F/layout, as shown here, here and here.

Related

Jframe.setContentPane(new JLabel([image])); background image not loading after built .jar

I am having a problem with loading images, as I am trying to load a background for my launcher. It works when I run it in Eclipse, but when I export it to a jar file, it doesn't. I have paged through the already asked questions, No luck.
Here is my code:
public void initializeJFrame(){
ImageIcon bg = new ImageIcon("src/background.png");
jb.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
if (jta.getText().length() < 3 || jta.getText().length() > 16) {
System.exit(-1);
} else {
try {
Runtime.getRuntime().exec(cmd, null, dir);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.exit(0);
}
}
});
jf.setSize(WIDTH,HEIGHT);
jf.setTitle("Cracked Launcher");
jf.setLayout(null);
jf.setContentPane(new JLabel(bg));
jf.setResizable(false);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t.start();
My image is in the src folder, nothing else. I cannot find what the problem is.
Thanks for your support.
ImageIcon bg = new ImageIcon("src/background.png");
This constructor takes a filename; it will not load resources from a jar. You want to pass a URL generated by a classloader, like so:
ImageIcon bg = new ImageIcon(getClass().retResource("background.png"));

repetitive header/footer issue on creating ms word document using apache poi

I have a project which creating ms word document. In this word document, I want to create header/footer. To do this I wrote this codes
public static void header_footer(String SalesOrder,String type) throws InvalidFormatException, IOException
{
XWPFHeaderFooterPolicy headerFooterPolicy = document.getHeaderFooterPolicy();
if (headerFooterPolicy == null)
headerFooterPolicy = document.createHeaderFooterPolicy();
XWPFHeader header = headerFooterPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);
XWPFTable asd= header.createTable(1, 2);
asd.setTableAlignment(TableRowAlign.LEFT);
XWPFTableRow row;
XWPFTableCell cell,cell2;
CTHeight ht;
CTTrPr trPr;
CTTblWidth cellWidth;
row= asd.getRow(0);
trPr = row.getCtRow().addNewTrPr();
ht = trPr.addNewTrHeight();
ht.setVal(BigInteger.valueOf(-1070));
cell=row.getCell(0);
XWPFParagraph parag=document.createParagraph();
parag = cell.getParagraphArray(0);
XWPFRun r1=parag.createRun();
InputStream pic = access_connection.class.getResourceAsStream("page1_header.png");
r1.addPicture(pic, XWPFDocument.PICTURE_TYPE_PNG, imgFile2, Units.toEMU(160), Units.toEMU(55));
cellWidth = cell.getCTTc().addNewTcPr().addNewTcW();
cellWidth.setW(BigInteger.valueOf(3500));
cell2=row.getCell(1);
cellWidth = cell2.getCTTc().addNewTcPr().addNewTcW();
cellWidth.setW(BigInteger.valueOf((short)20000));
parag=cell2.getParagraphArray(0);
parag.setVerticalAlignment(TextAlignment.CENTER);
parag.setAlignment(ParagraphAlignment.CENTER);
cell2.setVerticalAlignment(XWPFVertAlign.CENTER);
XWPFRun r2=parag.createRun();
r2.setFontSize(14);
r2.setFontFamily("Calibri");
r2.setText("TURKISH ENGINE CENTER SHOP VISIT REPORT");
r2.addBreak();
r2.setText("ESN "+SalesOrder.substring(1, 7)+" Istanbul,TURKEY");
XWPFFooter footer = headerFooterPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT);
XWPFParagraph parag2= footer.createParagraph();
XWPFRun run3=parag2.createRun();
XWPFRun run4=parag2.createRun();
run3.setFontFamily("Arial");
run4.setFontFamily("Arial");
run3.setBold(true);
run4.setItalic(true);
run3.setFontSize(8);
run4.setFontSize(9);
run3.setText("U.S. Export Classification: EAR ECCN 9E991");
run3.addBreak();
run4.setText("Printed by TEC Local EVM System");
XWPFParagraph parag3= footer.createParagraph();
XWPFRun run5=parag3.createRun();
parag3.setAlignment(ParagraphAlignment.RIGHT);
run5.setFontSize(7);
run5.setFontFamily("Arial");
run5.setText("Page ");
run5.getCTR().addNewPgNum();
// footer.setCommited(true);
try {
FileOutputStream input = new FileOutputStream(word_saveas_file+SalesOrder+"_"+type+"_Report.docx");
document.write(input);
input.close();
// input.flush();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I'm running my project from .jsp web page on tomcat server. When I run my project first time, everything running correctly. But when I run my project second time without stopping or restarting tomcat server, header/footer is repeating. I don't understand why only header/footer repeating. I'm creating ms word documents which are different names but still have this problem.
public static void Start(String SalesOrder, String path,String type) throws SQLException, ClassNotFoundException {
baslik[0]="ATA";
baslik[1]="LID";
baslik[2]="PN";
baslik[3]="QPE";
baslik[4]="SV";
baslik[5]="IS";
baslik[6]="RS";
baslik[7]="REP";
baslik[8]="Defect";
baslik2[0]="PN";
baslik2[1]="NEW";
baslik2[2]="REP";
baslik2[3]="SV";
baslik2[4]="Information Only";
try {
start_page_1(SalesOrder,path,type);
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
start_page_2(SalesOrder,type);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
header_footer(SalesOrder,type);
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
eng_general(SalesOrder);
oil_sys(SalesOrder);
GroupName(1);
partoff(SalesOrder,type);
//baglanti= DriverManager.getConnection("jdbc:ucanaccess://"+db_file,db_username,db_password);
//sorgu=baglanti.createStatement();
//deneme=sorgu.executeQuery("SELECT * FROM TableRun");
System.out.println("Process Completed");
}
public static void Start_PDM(String SalesOrder, String path,String type) throws SQLException, ClassNotFoundException, IOException {
baslik[0]="ATA";
baslik[1]="LID";
baslik[2]="PN";
baslik[3]="QPE";
baslik[4]="SV";
baslik[5]="IS";
baslik[6]="RS";
baslik[7]="REP";
baslik[8]="Defect";
baslik2[0]="PN";
baslik2[1]="NEW";
baslik2[2]="REP";
baslik2[3]="SV";
baslik2[4]="Information Only";
try {
start_page_1(SalesOrder,path,type);
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
start_page_2(SalesOrder,type);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
header_footer(SalesOrder,type);
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
GroupName(1);
partoff(SalesOrder,type);
/*try {
Runtime.getRuntime().exec("taskkill /F /IM java.exe");
Runtime.getRuntime().exec("net start java");
System.exit(0);
} catch (Throwable e) {
} */
baglanti.close();
//baglanti= DriverManager.getConnection("jdbc:ucanaccess://"+db_file,db_username,db_password);
//sorgu=baglanti.createStatement();
//deneme=sorgu.executeQuery("SELECT * FROM TableRun");
System.out.println("Process Completed");
}
I'm using first method for create word document with eng_general and oil_sys methods. In the second method I'm creating word document without eng_general and oil_sys.

Scrollbar in JEditorPane in a Rectangle

I have a JEditorPane that is inside a rectangle in a window so that it doesnt fill the whole window. However when the HTML page gets too big, it cuts it off instead of putting in a scrollbar, I know I need a JScrollpane or something, but I dont want the scrollbar on the whole window, only inside the rectangle.
Here is a snippet of my code (rweb is already defined as a Rectangle):
JEditorPane web = new JEditorPane();
web.setEditable(false);
try {
web.setPage("http://www.google.com");
}catch (IOException e) {
web.setContentType("text/html");
web.setText("<html>Could not load webpage</html>");
}
web.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if(Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
});
rweb = new Rectangle(0, 0, width, 600);
web.setBorder(null);
web.setBounds(rweb);
window.add(web);
You never add the JEditorPane to a JScrollPane. Text components don't have scroll support by themselves.
Try using window.add(new JScrollPane(web)); instead
Take a look at How to use scroll panes for more details
ps- web.setBounds(rweb); will only work if you are using a null layout and if you are, you'd be better of using a EmptyBorder or a layout manager that provided the ability to specify insets, like GridBagLayout

Image is not displaying in JFrame

My image was displaying properly before I had a JButton on top of it. Now that I have added a JButton to my code, my image does not display. In the ActionPerformed method I am telling the button to setVisbible(false). When I click the button, it disapears and all that is behind it is the background.
public class Main extends JFrame implements ActionListener {
public static void main(String[] args) {
Main main = new Main();
}
ImageIcon GIF = new ImageIcon("src/Zombie Steve gif.gif");
JButton button = new JButton("Click me!");
JLabel Label = new JLabel(GIF);
public Main() {
button.addActionListener(this);
Label.setHorizontalAlignment(0);
JFrame Frame = new JFrame("zombieSteveGIF");
Frame.setSize(650, 650);
Frame.setVisible(true);
Frame.add(Label);
Frame.add(button);
Frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
while (true) {
Frame.getContentPane().setBackground(Color.BLUE);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Frame.getContentPane().setBackground(Color.GREEN);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Frame.getContentPane().setBackground(Color.RED);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void actionPerformed(ActionEvent e) {
button.setVisible(false);
}
}
Your problem is that you have a BorderLayout (the default for JFrames), and you are adding two components in the same position. The default is BorderLayout.CENTER, and by adding two components with just the default constraints, the first one is removed and the second put in its place.
As for fixing your problem, what do you want to achieve? If you want the components to show on top of one another, you can use the OverlayLayout. If you don't want this, try some other layout manager.

How to manage a JInternalFrame calling another JInternalFrame?

I have a JDesktopPane with this code.
public class Menu extends JFrame implements ActionListener{
/**
* Creates new form Portada
*/
public static JDesktopPane desktop;
public JDesktopPane getDesktop() {
return desktop;
}
public Menu() {
desktop = new JDesktopPane();
setContentPane(desktop);
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
initComponents();
}
}
then i add the new components like this
desktop.add(orden);
and when i want to call them i use
if(e.getSource()==jMenuItem1_1){
orden.setVisible(true);
desktop.setSelectedFrame(orden);
desktop.moveToFront(orden);
try {
orden.setSelected(true);
} catch (PropertyVetoException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
The problem i get is that when "orden" wants to pop out another JInternalFrame i use the next code.
searchSupplier.setVisible(true);
Main.getInstance().getPortada().getDesktop().add(searchSupplier);
Main.getInstance().getPortada().getDesktop()
.moveToFront(searchSupplier);
try {
searchSupplier.setSelected(true);
} catch (PropertyVetoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
When I execute the event more than 2 times i get the next error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: illegal component position
Where should i add the new JInternalFrame to the DesktopPane? or to Orden?, or What can i do to fix this error?
If the searchSupplier frame is already on the desktop, it is unlikely that you will able to add it again. Try using getParent to determine if the frame needs to be added
if (searchSupplier.getParent() == null) {
Main.getInstance().getPortada().getDesktop().add(searchSupplier);
}
searchSupplier.setVisible(true);
Main.getInstance().getPortada().getDesktop().moveToFront(searchSupplier);
try {
searchSupplier.setSelected(true);
} catch (PropertyVetoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Categories