Java

Swing-es JScrollPane probléma

Fórumok

Üdv!

Bele is csapok a lecsóba:

Van egy JPanelem (nevezzük main-nek) ez a main JPanel tartalmaz egy "body" JPanel-t. Azt szeretném, hogy minden tartalom ami ebben a body JPanel-ben van scrollozható legyen, ha a tartalom túl nagy. A tartalom lehet JTable, egy kép, JLabel, JTextArea stb...

Erre azt a megoldást találtam ki, hogy a body-t bele raktam egy JScrollPane-ba, a JScrollPante-t a main-be. Ekkora ha a body-ba tartalmat teszek ami túl hosszú, akkor megjelenik a scrollbar. Igen ám, de ha belerakok egy JTextArea-t a body-ba a scrollbar mögé is befolyik a szöveg.

Az igazi megoldás az lenne, ha direkt kapna a JTextArea egy JScrollPane-t, de mint mondtam a tartalom változhat, ezért inkább az egész body-t scrollozhatóvá akarom tenni.
Az érdekes az, hogy ha fogom a JTextArea tartalmát és mögé rakok még 4-5 entert akkor nem folyik a scrollbar alá, foggalmam sincs, hogy miért.

Itt egy kis kód, hátha ez jobban szemlélteti a dolgot:


class Display:

JPanel main = new JPanel();

JPanel setBodyBox{
...
/* BOX BODY BEGIN */
bodyBox = new JPanel(new GridBagLayout());
GridBagConstraints boxBody_gbc = new GridBagConstraints();
boxBody_gbc.gridx = 0;
boxBody_gbc.gridy = 2;
boxBody_gbc.weightx = 1.0;
boxBody_gbc.weighty = 1.0;
boxBody_gbc.anchor = GridBagConstraints.FIRST_LINE_START;
boxBody_gbc.fill = GridBagConstraints.BOTH;
boxBody_gbc.insets = new Insets(TerminalConstants.FLOW_BOX_BODY_MARGIN_TOP, 0, 0, 0);
bodyBox.setBackground(TerminalConstants.FLOW_BOX_BODY_BG);
/* BOX BODY END */

JScrollPane scrollPane = new JScrollPane(bodyBox);
scrollPane.setBorder(BorderFactory.createEmptyBorder());
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

main.add(scrollPane, boxBody_gbc);

return bodyBox;
}

class Valami extends Display:

valamiInitGui{
JPanel bodyBox = setBodyBox();

GridBagConstraints boxBody_gbc = new GridBagConstraints();
boxBody_gbc.gridx = 0;
boxBody_gbc.gridy = 0;
boxBody_gbc.weightx = 1.0;
boxBody_gbc.weighty = 1.0;
boxBody_gbc.anchor = GridBagConstraints.FIRST_LINE_START;
boxBody_gbc.fill = GridBagConstraints.HORIZONTAL;
boxBody_gbc.insets = new Insets(TerminalConstants.FLOW_FORM_PADDING, 0, 0, 0);

setupPictures(bodyBox , flowBox_gbc);

boxBody_gbc.gridx = 0;
boxBody_gbc.gridy = 1;
boxBody_gbc.gridwidth = 2;
boxBody_gbc.fill = GridBagConstraints.BOTH;
boxBody_gbc.anchor = GridBagConstraints.LINE_START;
boxBody_gbc.insets = new Insets(40, 20, 0, 0);

JTextArea textArea = new JTextArea();
textArea.setOpaque(false);
textArea.setEditable(false);
textArea.setFont(TerminalConstants.FONT_BOX_BODY_HINT2);
textArea.append("Sok sok szöveg");
textArea.setWrapStyleWord(true);
textArea.setLineWrap(true);

bodyBox.add(textArea, boxBody_gbc);
}

Java User Meetings XX. - 2012. november 21. 18 óra

Fórumok

Örömmel jelentjük be a JUM következő, huszadik alkalmát!

A következő előadók és témák várhatóak:
Tamás Viktor a Devoxx 2012 konferenciáról számol be,
Ujhelyi Zoltán az Eclipse plug-in fejlesztés rejtelmeibe vezet be, majd
Marhefka István mutatja be egy startup, egy közösség brainstorming platform technológiai stackjét.

Bővebben, illetve friss információk: http://wiki.javaforum.hu/pages/viewpage.action?pageId=29688114

eclipse+maven+tomcat+spring

Fórumok

Hali

A címben szereplő kombinációval szeretnék egy projectet indítani, de elég nehézkezen halad.
Több dolog is van, ami nem világos:
- Ha tomcat:deploy-t indítok, akkor elvárja, hogy fusson a tomcat, ami esetemben egy kézzel letöltött és indított tomcat 7, viszont ha tomcat:run-t, akkor ő akarja elindítani, ha már fut a tomcat, szól, hogy foglalt a port. Viszont ő 6os tomcat-et indít, amit én special le sem töltöttem.
- Semmi hibavisszajelzést nem látok. Szal teljes projecteket töltöttem le tutorialokból, amik nem indulnak, de fogalmam sincs, hogy miért, mert bedeployolja, és amikor megnyitom az URL-t, egyszerűen HTTP Status 404. Kipróbáltam, hogy pl egy nagy nehezen beizzított project egyik XML-jéből kitöröltem egy tag lezárását, és szó nélkül bedeployolja, csak nyilván íg már nem fut, és 404, de semmi hibát nem ír ki a tomcat console.
- Sőt, a project, ami végre elindul deployolva, ha run-nal futtatom, akkor nem indul. 404.
- úgy szoktam indítani a deployt, hogy a pon-pn jobb klikk, run as >> build, és ott már szerepelnek a bejegyzések. Nem lhet ehhez valami gyorbillentyűt rendelni?

Ez csak nekem okoz ennyi bénázást? Hol a fenébe kéne, hogy megjelenjenek a hibaüzenetek arről, hogy hélo pajti, nem jó az XML-ed!?

köszi

TreeSelectionEvent-ből File objektum kinyerése

Fórumok

Sziasztok!

A következő a problémám: Szeretnék írni egy primitív CsoportosÁtnevezőt. (Az átnevező része egyelőre lényegtelen.)

A felépítése a következő: bal oldalon van egy JTree amiben lehet tallózni a könyvtárak között, jobb oldalon pedig egy JTable, ahol az éppen aktuális könyvtár tartalmát listázza ki. (Itt lehet majd később bepipálni, hogy mely fájlokat nevezze át, stb. )

A probléma ott jön, hogy nem tudom megoldani azt, hogy a kijelölt könyvtár File objektumként átadódjon a táblázatomnak.

A táblázathoz Kirill Grouchnikov kódját használtam fel és némiképpen módosítottam (csak könyvtárakat jelenítsen meg).
talán így jobban látható --> http://pastebin.com/nYjsuq1t

import java.awt.BorderLayout;
import java.awt.Component;
import java.io.File;
import java.io.FileFilter;
import java.util.*;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

/**
* @author Kirill Grouchnikov
*/

public class FileTreePanel extends JPanel {

protected static FileSystemView fsv = FileSystemView.getFileSystemView();
private JTree tree;
//At first I was trying this - but it is wrong.
public static File current;

private static class FileTreeCellRenderer extends DefaultTreeCellRenderer {

private Map iconCache = new HashMap();
private Map rootNameCache = new HashMap();

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
FileTreeNode ftn = (FileTreeNode) value;
File file = ftn.file;
String filename = "";
if (file != null) {
if (ftn.isFileSystemRoot) {
filename = this.rootNameCache.get(file);
if (filename == null) {
filename = fsv.getSystemDisplayName(file);
this.rootNameCache.put(file, filename);
}

} else {
filename = file.getName();
}
}
JLabel result = (JLabel) super.getTreeCellRendererComponent(tree, filename, sel, expanded, leaf, row, hasFocus);
if (file != null) {
Icon icon = this.iconCache.get(filename);
if (icon == null) {
icon = fsv.getSystemIcon(file);
this.iconCache.put(filename, icon);
}
result.setIcon(icon);
}
return result;
}
}

private static class FileTreeNode implements TreeNode {

private File file;
private File[] children;
private TreeNode parent;
private boolean isFileSystemRoot;

public FileTreeNode(File file, boolean isFileSystemRoot, TreeNode parent) {
this.file = file;
this.isFileSystemRoot = isFileSystemRoot;
this.parent = parent;
this.children = this.file.listFiles(new FileFilter() {
//!Modification here - display only the directories
@Override
public boolean accept(File file) {
return file.isDirectory();
}
});
if (this.children == null) {
this.children = new File[0];
}
//obliviously wrong "solution" :(
current = file;
}

public FileTreeNode(File[] children) {
this.file = null;
this.parent = null;
this.children = children;
}

@Override
public Enumeration<?> children() {
final int elementCount = this.children.length;
return new Enumeration() {
int count = 0;

@Override
public boolean hasMoreElements() {
return this.count < elementCount;
}

@Override
public File nextElement() {
if (this.count < elementCount) {
return FileTreeNode.this.children[this.count++];
}
throw new NoSuchElementException("Nincs több elem.");
}
};
}

@Override
public boolean getAllowsChildren() {
return true;
}

@Override
public TreeNode getChildAt(int childIndex) {
return new FileTreeNode(this.children[childIndex],
this.parent == null, this);
}

@Override
public int getChildCount() {
return this.children.length;
}

@Override
public int getIndex(TreeNode node) {
FileTreeNode ftn = (FileTreeNode) node;
for (int i = 0; i < this.children.length; i++) {
if (ftn.file.equals(this.children[i])) {
return i;
}
}
return -1;
}

@Override
public TreeNode getParent() {
return this.parent;
}

@Override
public boolean isLeaf() {
return (this.getChildCount() == 0);
}
}

public FileTreePanel() {
super();
this.setLayout(new BorderLayout());

File[] roots = File.listRoots();

FileTreeNode rootTreeNode = new FileTreeNode(roots);
this.tree = new JTree(rootTreeNode);
this.tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

this.tree.setCellRenderer(new FileTreeCellRenderer());
this.tree.setRootVisible(true);
this.tree.addTreeSelectionListener(new JTreeSelectionListener());

JScrollPane jsp = new JScrollPane(this.tree);
this.add(jsp, BorderLayout.CENTER);
}

private class JTreeSelectionListener implements TreeSelectionListener {

@Override
public void valueChanged(TreeSelectionEvent jtsl) {
TreePath o = jtsl.getPath();
System.out.println(o);
System.out.println(current);

SelectionList.listBuilder(current);
}
}
}

A legfontosabb rész a végén van, itt kéne valahogyan File-t varázsolni a TreeSelectionEvent-ből. Benne hagytam még a rossz próbálkozásomat, de sajnos az nem jó... :(
pastebin --> http://pastebin.com/d6zST5BC

import java.awt.BorderLayout;
import java.awt.Color;
import java.io.File;
import java.io.FileFilter;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class SelectionList extends JPanel {

private static FilesData data;
private static JTable table;

public SelectionList() {
super();
data = new FilesData();
table = new JTable(data);

table.setFillsViewportHeight(true);
table.setShowGrid(true);
table.setGridColor(Color.BLACK);

JScrollPane jsp = new JScrollPane(table);
this.add(jsp, BorderLayout.CENTER);

}

public static void listBuilder(final File f) {
data.files.clear();
File[] fs = f.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isFile();
}
});
if (fs != null) {
for (File m : fs) {
Files ujFile = new Files(m, m.isHidden(), Menu.checkAll.getState());
if (!m.isHidden() || Menu.hiddenFilesVisibility.getState()) {
data.files.add(ujFile);
}
}
}
table.repaint();
}
}

A érdekes része a listBuilder függvény. Remélem ennyi információ elég, ha szükség van rá, felrakom a többi osztályt is.
Minden segítséget előre köszönök!

[megoldva] Jboss 7 EJB deploy timeouttal elszáll

Fórumok

Sziasztok!

A tárgyban nevezett alkalmazásszerverre költözünk 5.1-ről, és a segítségeteket szeretném kérni egy dologban, ahol elakadtam. Megcsináltam a modulokat, amik kellenek az EJBmhez, beállítottam függőségnek a manifestben, beállítottam a datasourceot ahogy kell. Deployolás közben elhasal. íme a log, amit generál:

14:48:34,863 INFO [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015876: Starting deployment of "02oaziscomputerdao-bean.jar"
14:48:34,967 INFO [org.jboss.as.jpa] (MSC service thread 1-11) JBAS011401: Read persistence.xml for ShopPool
14:48:35,113 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-2) JNDI bindings for session bean named SettingsService in deployment unit deployment "02oaziscomputerdao-bean.jar" are as follows:

java:global/02oaziscomputerdao-bean/SettingsService!hu.oaziscomputer.service.client.SettingsServiceLocal
java:app/02oaziscomputerdao-bean/SettingsService!hu.oaziscomputer.service.client.SettingsServiceLocal
java:module/SettingsService!hu.oaziscomputer.service.client.SettingsServiceLocal
java:global/02oaziscomputerdao-bean/SettingsService
java:app/02oaziscomputerdao-bean/SettingsService
java:module/SettingsService

... Ezt minden SessionBeanre kiírja, aztán

14:52:34,828 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "02oaziscomputerdao-bean.jar" was rolled back with failure message Operation cancelled
14:52:34,829 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015052: Did not receive a response to the deployment operation within the allowed timeout period [120 seconds]. Check the server configuration file and the server logs to find more about the status of the deployment.

_Dehát ezt a logba írta, hogy tudhatnék meg többet a logból??? :D_

A timeoutot már próbáltam fentebb állítani, de hiába. Ha valakinek van ötlete kérem ne tartsa magába.

Előre is köszi.

JTable celle háttérszíne

Fórumok

Szeretném megváltoztatni egy JTable objektum egy cellájának háttérszínét.
A neten van ezerrel példa, arra, hogy az egész oszlopnak hogyan változtassam meg.
De egyetlen cellának nem bírok rájönni hogyan.

E az egész tábláét változtatja:


tabla.setBackground(Color.blue);

Ez az egész oszlopét változtatja:


tabla.getColumnModel().getColumn(0).setCellRenderer(new BlackTableCellRenderer());

Nekem csak egyetlen cella színét kellene változtatnom.

Csinált már valaki ilyet?

Maven csomagépítés ügyfélre szabottan (best practices)

Fórumok

Hi,

A cím kb. a Maven customized release management best practices :) témakört fedné le :).

Van egy wicket alapú alkalmazásom mindenféle környezetfüggő properties fájllal megtűzdelve.

- Application.properties
A rendszer által használt általános paramétereket tartalmazza
- database.properties
host, db stb.
- log4j.properties

A cél az lenne, hogy az ügyfél környezetétől függően (db és egyéb paraméterek) tudjak war-t előállítani. Vidámabb lennék, ha nem kellene minden deploy után ezeket újra állítani. Erre várnám az ötleteket.

Köszönöm!

Wicket+Spring+Junit tesztelés

Fórumok

Hi,

Tudnátok valami stacket javasolni a fentire ? Kb. egy napja rágom át magam a különféle, leginkább elavult postokon, de nem jutottam túl messze.
Van néhány spring bean-em, amit használok, de a teszt eseteknél nem injektálódnak be automatikusan.
Köszönöm előre is!



package hu.xxx.xxx.main;

import org.springframework.context.ApplicationContext;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
import org.apache.wicket.util.tester.WicketTester;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author user
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"applicationContext.xml", "applicationContext-Security.xml"})
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class LoginPageTest  {

    @Autowired
    private ApplicationContext ctx;
    private WicketTester tester = null;

    @Before
    public void setUp() throws Exception {

        tester = new WicketTester(new MyApplication() {

            @Override
            protected void init() {
                SpringComponentInjector injector = new SpringComponentInjector(this, ctx);
                getComponentInstantiationListeners().add(injector);
                injector.inject(this);
            }
        });

    }

    @Test
    public void renderPage() {
        tester.startPage(HomePage.class);
    }
}



Keresztböngészős selenium teszt hogyan?

Fórumok

Már egy ideje keresek megoldást a fentire, de nem szeretne valahogy működni.
Jelenleg a Selenium IDE programmal felveszem a tesztet, majd FireFox-ban simán le is futnak.
Innen kiexportálom java-ba. Chrome-ra és IE-re is kibővítem. De itt, hol az egyik hol a másik browser nem működik a webdriverrel. Ráadásul sokkal lassabb is, mint Firefox pluginból futtatva.

Van valakinek működőképes megoldása?